Enrique Ortiz Casillas
Enrique Ortiz Casillas

Reputation: 577

Virtualenv installing a package in the global directory

I made sure to read this question and similar ones, but I couldn't find an answer to my problems.

My problem is: when I head into muy virtual env and activate it, if I install a package there, it is also installed elsewhere in my computer.

So, for example, if I type in the terminal:

cd home/Documents/Python/tests/my_virtual_env
source bin/activate

That activates the virtual environment. If I type:

pip3 install wget  #just an example package 

I see the installation process and I can run a .py script that uses wget. However, why is this package also installed elsewhere in my computer?

  1. I made sure I hadn't that package installed beforehand using pip3 list.
  2. I confirmed that package was installed elsewhere by running a .py script from other directories (using cd /etc.etc/ to change directory and then running it from there).
    1. I deactivated the environment in the right moment.

I also realized that if I uninstall that package within the virtualenv, it is also uninstalled elsewhere.

Thank you so much for your help.

Upvotes: 1

Views: 680

Answers (1)

sinoroc
sinoroc

Reputation: 22295

It could be that the pip3 command being executed is not actually tied to the virtual environment. So instead you could the following, which would work whether or not the virtual environment is activated:

$ path/to/my_virtual_env/bin/python3 -m pip install SomeProject

The following command should give you a relatively clear indication of where exactly the project has been installed, make sure it is in the site-packages directory of the virtual environment:

$ path/to/my_virtual_env/bin/python3 -m pip show SomeProject

So it should show something of the sort:

Name: SomeProject
...
Location: .../path/to/my_virtual_env/lib.python3.X/site-packages

However, why is this package also installed elsewhere in my computer?

The following shows where a binary is located:

$ which somecommand

It should be relatively easy to recognize if somecommand is in a Python virtual environment or not.

Upvotes: 1

Related Questions