Skip to content
Advertisement

How to install Python packages in a specific environment?

I installed Anaconda3 so I can create environments and install different packages in each environment. But I fail to understand the difference between the Python in

/usr/bin/python

and

/opt/anaconda3/bin/python

I can seem to access Python 3.6.5 Anaconda from both, why is that? And, what is the difference between both?

Furthermore, I would like to install packages to a single Python environment only.

Advertisement

Answer

When you are running python in the terminal, it is looking up your default path to your the python command. In this case, anaconda probably put a line in your shell profile specify the path to the anaconda version, which is why you are seeing it in the interpreter when you run python from either directory.

Secondly, you can set up a conda environment to download app specific dependencies without interfering with your default set up by

conda create --name myenv
source activate myenv
conda install packagename

This will install it in the myenv environment only. To deactivate the environment just run

source deactivate

Here is the documentation on that https://conda.io/docs/user-guide/tasks/manage-environments.html

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement