Skip to content

Instantly share code, notes, and snippets.

@danielTobon43
Last active August 22, 2023 15:46
Show Gist options
  • Save danielTobon43/1fb8a8933be389816a62e74591d09473 to your computer and use it in GitHub Desktop.
Save danielTobon43/1fb8a8933be389816a62e74591d09473 to your computer and use it in GitHub Desktop.
Conda environment tutorial

Create conda environment

  1. Download and install miniconda3: https://docs.conda.io/en/latest/miniconda.html
  2. Open Anaconda Prompt (miniconda3)
  3. conda create --prefix=conda-env python==3.8
  4. conda config --set env_prompt '({name}) <-- Just once
  5. conda activate conda-env
  6. conda install <package-name>
  7. conda install -c conda-forge <package-name>
  8. Inside conda-env, run: pip install <package-name>

Create an insolated conda environment

Conda envs aren’t globally isolated. The default behavior when creating a pip virtual environment is that when inside the new environment, you do not have access to globally installed pip packages. If you want access to global packages, you need to initialize your virtual environment with:

virtualenv env --system-site-packages

conda , on the other hand, lets you access global system packages by default. If you want the environment to be completely isolated from these global packages like with pip, you can create the conda environment based on a clone of an empty pip virtualenv.

  1. pip install virtualenv
  2. conda create --prefix=tmp-env python==3.8
  3. conda activate /tmp-env
  4. virtualenv empty-env <-- run this command with the tmp-env activated
  5. conda create --prefix=conda-env --clone empty-env <-- this will create an insolated conda-env with python==3.8

Note

Steps 4 and 5 in the insolated environment are necessary since virtualenv uses the default python interpreter in the current path.

References

@dtcMLOps
Copy link

Run conda init beforehand

make sure run conda init powershell in windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment