1

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?

user14717
  • 4,757
  • 2
  • 44
  • 68
  • `ls ~/venv/bin/` has pip in it? How about `which pip` after you have activated the virtualenv. – Jay Dec 17 '21 at 18:09
  • @Jay: You're right, no pip in `~/venv/bin/`. `which pip` fails after activating the virtualenv. – user14717 Dec 17 '21 at 18:18
  • I thought `pip` came standard with virtualenvs; for instance on another platform I have access to `which pip` is found in the `venv`; moreover it is not a symlink to a system `pip` . . . – user14717 Dec 17 '21 at 18:19
  • Right, there should be a `pip` in the `venv/bin`. Secondly the `~/venv/bin/python3` should not be a symlink.. How did you create the `virtualenv`? Try creating a fresh one, `virtualenv new_venv -p python3` and make sure that it has pip in `new_venv/bin` and `new_env/bin/python3` is not a symlink – Jay Dec 17 '21 at 18:22
  • The `python3` is a symlink to the system python3 on every platform I've tried . . .. – user14717 Dec 17 '21 at 18:23
  • Virtualenv created with `python3 -m venv .` – user14717 Dec 17 '21 at 18:23
  • I created a new venv from scratch. No `pip` is in `~/venv/bin` on the platform of interest; however it is on every other platform I've tried. – user14717 Dec 17 '21 at 18:29
  • That's weird, what platform are you on? Try installing `virtualenv` using `pip install virtualenv` and then try creating one from there `virtualenv new_venv -p python3` and see if new_venv/bin has everything or not. – Jay Dec 17 '21 at 18:32
  • Platform is CentOS7. – user14717 Dec 17 '21 at 18:46
  • Can't use `virtualenv` because that's python2 correct? – user14717 Dec 17 '21 at 18:47
  • 1
    @Jay: Fixed it via `python3 -m virtualenv .`; looks like you were basically on the right track. Want to post an answer? – user14717 Dec 17 '21 at 18:50

1 Answers1

3

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
Jay
  • 2,431
  • 1
  • 10
  • 21
  • [Why venv is preferred over virtualenv](https://stackoverflow.com/questions/41573587/what-is-the-difference-between-venv-pyvenv-pyenv-virtualenv-virtualenvwrappe/47559925#47559925) – Emil Carpenter Jan 03 '22 at 17:44