Skip to content

Instantly share code, notes, and snippets.

@NicHub
Last active September 6, 2020 11:34
Show Gist options
  • Save NicHub/616740d41003b2abebead6e2d57e441a to your computer and use it in GitHub Desktop.
Save NicHub/616740d41003b2abebead6e2d57e441a to your computer and use it in GitHub Desktop.
Python Virtual Environment cheat sheet

Anaconda

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

Most needed functions

conda env list
conda create --name myenv python=3.6.9
conda activate myenv
conda info --envs
conda deactivate
conda config --set changeps1 false
conda remove --name myenv --all

Environment file

https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-file-manually

conda env export > environment.yml
conda env export --from-history > environment_from_history.yml

Bare Python (no Anaconda)

https://docs.python.org/3/tutorial/venv.html

With bare python, the virtual environnement is stored at the same location of your project, so there is no centralized location and thus no commands to list all environments created on a machine.

The environment must be activated in each terminal used.

Most needed functions

cd ./dir_to_store_the_env_that_is_where_your_project_will_be_stored
python3 -m venv myenv
source myenv/bin/activate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment