conda create -n myenv python=3.7
conda activate myenv- Create a file named
environment.ymlsimilar to the example below:name: myenv dependencies: - python=3.7 - pandas - numpy - Create the environment with by executing
conda env create -f environment.yml- If you are in the directory where
environment.ymllives, just runconda env create
- If you are in the directory where
- Activate the environment with
conda activate myenv
- Add the new package you want to add to the environment in the yaml file
- Execute
conda env update --file environment.yml
See note below on Setting channels in environment file for an alternative approach
In environment.yml file, do the following:
name: toxic_comment_kaggle
dependencies:
- pip
- pip:
- flask_restplus
conda create --name <name of cloned env> --clone <env I want to clone>
conda env list
- Not a great idea if this is going to be used to create an environment in another operating system (see best practices below)
- Specifically, the package versions exported using this approach may not exist in an operating system different from the one where the environment was originally created
- If you insist in doing this, the command is
conda env export > environment.yml
conda remove --name myenv --all
- Install autoenv:
pip install autoenv && source activate.sh - Create a .env file with
source activate <env name>in it inside the folder containing the code for the virtual environment - Now every time you enter that folder from the command line the virtual environment will be activated.
- See below for great guides on best practices in regards to creation and management of environments:
Occasionally, the package you need is not available in the default channel used by the conda package manager. To set the channel from which to install your package, list them under a channels heading in your environment yaml file:
name: myenv
channels:
- defaults
- conda-forge
dependencies:
- flask_restplus
conda-forge contains packages that may not be in the Anaconda repository of packages. Specifying this channel will allow you to install such packages that do not exist in the default channel.
Sometimes there are issues with installing packages using different package managers in the same environment. One example is when one uses pip inside an environment create by conda. To avoid these issues, don't install the package using pip if you are creating an environment using conda. Instead, look for the channel in which a package lives and specify the channel in the yaml file (as shown in the example above).
- TensorFlow on CPU
- create conda environment using the yml file, but don't include tensorflow in the file
- Once the environment is set up and activated, install tensorflow following command:
conda install -c https://conda.anaconda.org/jjhelmus tensorflow
- TensorFlow on GPU (machine with a GPU)
- Create the environment, again using the yml file but making sure it does not have TensorFlow
- In the activated environment,
pip uninstall tensorflow(this should have been installed along with keras) - Then install the GPU version of TensorFlow:
pip install tensorflow-gpu