I have a fresh install of Ubuntu 24.04. I added pip with the usual sudo apt install python3-pip
, and went to install some packages, but got the error: externally-managed-environment. This was all quite new to me, so I did some reading about venv
. Using PyCharm, I attached a virtual environment to my Python project at /home/colin/Dropbox/codebase/Python
. All seems to be going well so far. I opened up a terminal and ran:
source /home/colin/Dropbox/codebase/Python/venv/bin/activate
and now I’m in the virtual environment. Next I try to install a package with either:
pip install requests
python3 -m pip install requests
In both cases I get ModuleNotFoundError: No module named 'pip'
. Okay, fair enough, my previous install of pip was for the system, and isn’t visible in the virtual environment. So I try to install pip while in the venv:
sudo apt install python3-pip
and get:
python3-pip is already the newest version (24.0+dfsg-1ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 16 not upgraded.
Huh. Okay. I’m still in the venv, and try:
which pip
and it returns:
/home/colin/Dropbox/Codebase/Python/venv/bin/pip
So what am I doing wrong here? Why can’t I install packages with pip in my venv? It might be worth adding that I was following instructions from here for all this, but it doesn’t mention this issue.
2
Answers
As a commenter suggested, I've deleted the venv and created a new one outside Dropbox. However, I also did this at the terminal, rather than using PyCharm to create the venv. So I've actually changed two things. One of the two has done the trick, as I'm not having any problems now.
I’m experiencing the same frustration.
I confirmed that python3-setuptools, python3-wheel, and python3-pip were up-to-date.
I even created a venv manually thus: python -m venv .venv
And while pycharm 2024.1.2 (Community Edition) can see the .venv/bin/python file, it declares it to be "invalid", and won’t allow it to be used.