Ben Chuanlong Du's Blog

It is never too late to learn.

Tips on Conda

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

  1. conda and executables installed by conda might not be able to run by sudo directly. If this happends, use the full path of the executable or add the option -E "PATH=$PATH" to sudo.

    sudo -E env "PATH=$PATH" <command> [arguments]
    
  2. By defaut, conda installs things into /opt/conda.

Download Archives

https://repo.anaconda.com/miniconda/

https://repo.anaconda.com/archive/

Conda Environment

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

Create a Conda Virtual Environment

Create a conda virtual environment with Python 3.7, numpy, pandas and scikit-learn installed.

conda create -n myenv python=3.7 numpy pandas scikit-learn

Create a conda virtual environment from a YAML configuration file.

conda env create -n myenv --file myenv.yml

If you have issues creating a conda virtual environment (e.g., due to package not found in the current conda channel), you can create a bare conda virtual environment, install pip into the environment and then use pip to install the needed packages. For example, the below code creates a conda virtual environment with the Python package optimuspyspark installed.

conda create -n optimus
conda activate optimus
conda install pip
pip install optimuspyspark

Be careful though, as pip in a virtual environment sometimes installs packages into global location rather than your virtual environment. This won't affect usage of your virtual environment locally, generally speaking. However, if you want to package your virtual environemnt using conda-pack and use it somewhere else, the Python packages installed outside the virtual environemnt won't be packed. Make sure to use conda list -n env_name to check that the Python packages are installed into the virtual environment before you pack it using conda-pack. If the issue appears, you can always manually specify the installation location for pip.

Activate a Conda Virtual Environment

conda activate myenv

Pack a Conda Virtual Environment

A conda virtual environment can be packed (conda-pack required) into a tar.gz file and be used on other machines with the same type of OS. Notice that all packages in a conda virtual environment must be managed by conda (rather than pip) so that it can be packed by conda-pack.

conda pack -n myenv -o myenv.tar.gz

Deactivate a Conda Environment

conda deactivate myenv

Remove a Conda Environment

conda env remove -n myenv

Administering a multi-user conda installation

https://conda.io/docs/user-guide/configuration/admin-multi-user-install.html

My Conda Packages

https://anaconda.org/legendu/sqlalchemy-teradata

References

https://conda.io/docs/user-guide/tutorials/build-pkgs-skeleton.html

https://stackoverflow.com/questions/41060382/using-pip-to-install-packages-to-anaconda-environment

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html

Conda Cheatsheet

Conda Cheatsheet

Comments