Conda - Env and Package manager for Python¶
What is conda?
- Conda is a powerful environment and package manager.
- Create multiple environments with different versions of Python with different sets of libraries
- easily switch between environments
- http://anaconda.org/ provides free hosting for Python libraries
- conda helps to easily search for, install libraries and also to keep them up to date
Learn resources:
- getting started: http://conda.pydata.org/docs/test-drive.html#managing-environments
- reference doc: http://conda.pydata.org/docs/
Create a new environment¶
conda create --name <name_of_env> package=version
conda create --name devsummit_precon python=3.6
conda create --name data_sci_proj scipy pandas
Check if new folder was created in C:\anaconda3\envs
Activating environemnts¶
activate pro_devsummit_handson
search packages¶
conda search <package name>
conda search --channel <channel name> <package name>
conda search beautifulsoup
get info about a package¶
conda info <package name> ## gives you all dependencies
conda info --channel esri arcgis
Install packages¶
conda install <package name>
conda install pandas
conda install requests
conda instal --channel <channel_name> <package name>
conda install --channel esri arcgis
conda install -c esri arcgis
List all packages in current active environment¶
conda list
conda list nb* # wild card search
Remove a package¶
conda remove <package name>
Remove an environment¶
conda env remove --name <name of env>
conda env remove --name devsummit_precon
But you would most likely want to clone the ArcGIS Pro's Python environment so you can experiment without messing up the default one
conda create --name propy_clone --clone arcgispro-py3
Starting Jupyter notebook in a different directory¶
For the most part you can cd
to desired directory after activating your environment and start the notebook. But if you cannot do it:
jupyter-notebook --notebook-dir=D:\code\my_notebooks
Exporting an environment to a file¶
It is useful to export your environment to a environment.yml
file and include it in your repository. This allows replicating the project in a different computer by you or someone else.
conda env export --name your_env_name --file your_env_name.yml
This creates the .yml
file with version number and source repo for all your packages. Thus, this file is specific for a particular OS and Python build version.
To create an agnostic file, use
conda env export --name your-env-name | cut -f 1 -d '=' > your-env-name.yml
This strips out the version numbers, enabling you to upgrade to newer versions of the packages.
Install from an environment file¶
To create a new environment from this file, run
conda env create -f your_env_file.yml