Chase Roberts
Chase Roberts

Reputation: 9376

Conda - package installing to the root environment instead of active environment

I have an environment set up on my windows machine using Conda. And when I try to install a package, it is not installing to the active environment, but instead, to the root environment. What's the deal.

(science) C:\Users\user>conda info --envs
# conda environments:
#
science                *  C:\Users\user\Anaconda3\envs\science
root                      C:\Users\user\Anaconda3

I am active in my science environment, I try to install a package using pip.

pip install git+https://github.com/peplin/pygatt

But when I list the installed packages in the active environment:

(science) C:\Users\user>conda list
# packages in environment at C:\Users\user\Anaconda3\envs\science:
#

There are none. If I deactivate my environment and try conda list again, it shows that it installed to the root environment. This is not the desired behavior.

(science) C:\Users\user>deactivate

C:\Users\user>conda list
# packages in environment at C:\Users\user\Anaconda3:
#
_license                  1.1                      py36_1
alabaster                 0.7.9                    py36_0
anaconda                  4.3.1               np111py36_0
...
pygatt                    3.1.1                     <pip>
...

What am I doing wrong?

I tried creating a second environment. If I install pygatt to the second environment and then swap over to the first environment and try pip list then the pygatt is in the first environment as well. It's like these environments don't do what they are supposed to.

Upvotes: 4

Views: 7003

Answers (1)

Felix Kreuk
Felix Kreuk

Reputation: 303

It seems that you are using the root pip, this is why you don't see any of your installed packages inside your virtual environment.

To use the pip specific to a virtual environment:

  • first install pip in the virtual env: conda install -n science pip (now the science environment will have its own pip).
  • Then, locate that pip file wherever your conda environments are stored (for me it's .../anaconda/envs/).
  • Now, you can install your packages using that local pip file something along the lines of: .../anaconda/envs/science/bin/pip install something.

The thing is, unless you specify to conda that you want to install something specifically to a virtual env, it will end up in the root env (I'm not sure if this is by design, but this is what happenes on my machine). So if you want to install to a virtual env:

  • conda install -n env_name package_name if it's a conda install.
  • .../anaconda/envs/science/bin/pip install something if it's a pip install.

Upvotes: 7

Related Questions