Useful Anaconda Commands
Anaconda is a python distribution
Useful commands
Here are several useful commands for conda.
Environments
Environments are python installations that use a specific collection of packages.
1
conda create --name ENVNAME python=VER.NUMBER
Print all environments
1
conda env list
Print information of all packages in the active environment
1
conda list
Save list of packages in active environment
1
Package Installation
To install a package, use
1
conda install [-y] PACKAGE_NAME
Package Version:
Name | Operand | Example | Result |
---|---|---|---|
Fuzzy | = | numpy=1.1 | 1.11.0, 1.11.1, 1.11.2, etc |
Exact | == | numpy==1.11 | 1.11.0 |
Newer than | >= | numpy>=1.11 | versions newer than 1.11.0, less than is similar |
Or | | | numpy=1.11.1|1.11.3 | 1.11.1 OR 1.11.3 |
Range | >=,< | numpy>=1.8,<2 | 1.8.0,1.8.1,… 1.9.0, 1.9.1,….1.9.999999 NOT 2 |
Copy Environments
Local Machine Copy:
1
conda create --name CLONED_ENV_NAME --clone ENV_TO_CLONE
Cross Machine/Operating Systems
On machine with master environment active:
1
conda env export environment.yml
On slave machine(s):
1
conda env create -f environment.yml
New enviroments will be named __.yml.
For machines using the same OS, a plain-text file alternative would be: Master machine:
1
conda list --explicit PACKAGE_LIST.txt
Slave machine(s):
1
conda create --name NEW_ENV_NAME --file PACKAGE_LIST.txt
Conda-Pack
Rather than constructing environments from a list, an entire repo can be copied. Useful for complex installations.
Install conda-pack
1
conda install -c conda-forge conda-pack
Master machine:
1
conda pack -n MY_ENV # Pack environment MY_ENV into MY_ENV.tar.gz
On slave machine(s):
1
2
3
4
5
6
7
8
9
mkdir -p MY_ENV # or create manually
tar -xzf MY_ENV.tar.gz -C my_env # unzip environment
source MY_ENV/bin/activate # activate the environment
(MY_ENV) $ python # Run Python from in the environment
(MY_ENV) $ conda-unpack # Cleanup prefixes from in the active environment.
Read more here .
Set up Conda to PATH variable (Windows)
For automatons, it is useful to set up Conda to run from the command line
- Get conda’s path In ‘anaconda prompt’ run
1
where conda
Which should return something like:
1 2 3
C:\\Users\\USERNAME\\PATH_TO\\anaconda3\\Library\\bin\\conda.bat C:\\Users\\USERNAME\\PATH_TO\\anaconda3\\Scripts\\conda.exe C:\\Users\\USERNAME\\PATH_TO\\anaconda3\\condabin\\conda.bat
Make a note of these paths
Open up Environmental Variables Under ‘System Properties -> Advanced -> Environment Variables’
- Under ‘System Variables’ (Second entry), edit ‘Path’ Add three entries similar to the ones found in step one:
1 2 3
C:\\Users\\USERNAME\\PATH_TO\\anaconda3 C:\\Users\\USERNAME\\PATH_TO\\anaconda3\\Scripts C:\\Users\\USERNAME\\PATH_TO\\anaconda3\\Library\\bin