Why does pip list not work correctly within a virtual environment created by pipx?

3.1k views Asked by At

I'm on a Linux/Ubuntu system, in a folder designated by pyenv as Python 3.8.1. I've install pipx using pip install pipx. If I install an application (cowsay), and activate the virtual environment for the application, pip lists my globally installed packages. Why I'm I not seeing the site packages for the cowsay install when the virtual environment is activated?

You can see from the example below that pip list gives me the same result regardless of the activation status of the virtualenv? I know that during project development, this is not the observed response. When inside a venv, pip list gives me the site packages installed in the venv.

pipx --verion
0.15.5.1

pip --version    
pip 20.2.3 from /home/steve/.pyenv/versions/3.8.1/lib/python3.8/site-packages/pip (python 3.8)


cd /home/steve/.local/pipx/venvs/
source activate cowsay/bin/activate

(cowsay):~/.local/pipx/venvs$ pip list
Package     Version
----------- --------
argcomplete 1.12.1
click       7.1.2
distro      1.5.0
packaging   20.4
pip         20.2.3
pipx        0.15.5.1
pyparsing   2.4.7
setuptools  41.2.0
six         1.15.0
userpath    1.4.1
(cowsay) :~/.local/pipx/venvs$ deactivate

:~/.local/pipx/venvs$ pip list
Package     Version
----------- --------
argcomplete 1.12.1
click       7.1.2
distro      1.5.0
packaging   20.4
pip         20.2.3
pipx        0.15.5.1
pyparsing   2.4.7
setuptools  41.2.0
six         1.15.0
userpath    1.4.1
1

There are 1 answers

2
wim On BEST ANSWER

Your pip command is not actually using the venv. Checking type pip will tell you where it is really resolved. pipx won't create a console script for pip within the venv, because there is no need.

The console scripts created for the venv, including a cowsay executable and a python symlink on $PATH, will be under:

~/.local/pipx/venvs/cowsay/bin

But the console script for the pip installation will have been created under a location which is not on $PATH:

~/.local/pipx/shared/bin

You should still be able to see cowsay lib within the actual venv like this:

python -m pip list

You might wonder why python -m pip is working when pip is not? In fact, the pip installation is shared between venvs, and you should be able to see the path file hack which sets that up here:

~/.local/pipx/venvs/cowsay/lib/python3.8/site-packages/pipx_shared.pth