Skip to content
Advertisement

No module named pip which using virtualenv-based python

When running the system-installed python, I can find pip:

% which python3
/usr/local/bin/python3
% python3 --version
Python 3.9.7
% /usr/local/bin/python3 -m pip --version
pip 21.3.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

However, if I create a virtualenv with this python3 and activate it, then I can no longer find pip:

% which python3
~/venv/bin/python3
% ls -la `which python3`
~/venv/bin/python3 -> /usr/local/bin/python3
% python3 -m pip --version
~/venv/bin/python3: No module named pip

I am completely baffled by this.

What is it about reading through a symlink that could make pip disappear?

Advertisement

Answer

The python’s venv module introduced in python 3.3 is different from virtualenv and has a subset of virtualenv‘s features.

From https://virtualenv.pypa.io/en/latest/

The venv module does not offer all features of this library, to name just a few more prominent:

  • is slower (by not having the app-data seed method)
  • is not as extendable, cannot create virtual environments for arbitrarily installed python versions (and automatically discover
    these),
  • is not upgrade-able via pip,
  • does not have as rich programmatic API (describe virtual environments without creating them).

So an environment created using venv does not have a separate pip installed so I would recommend using virtualenv instead.

You can install the virtualenv module by running

pip3 install virtualenv

Create a new virtualenv in the current directory –

python3 -m virtualenv .

or you can also use

virtualenv env_name -p python3
3 People found this is helpful
Advertisement