After a system update to Ubuntu 20.04, I've had various issues with python. The current problem is that I cannot create a virtual environment:
python3 -m venv env
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt-get install python3-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/XXX/my-project/env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
To find out more about why it is failing I ran
./env/bin/python3 -Im ensurepip --upgrade --default-pip
:
/env/bin/python3: Error while finding module specification for 'ensurepip.__main__' (ImportError: cannot import name '_bundled' from partially initialized module 'ensurepip' (most likely due to a circular import) (/usr/lib/python3.9/ensurepip/__init__.py))
Of course I tried the suggested step with sudo apt-get install python3-venv
:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
python3-venv : Depends: python3.8-venv (>= 3.8.2-1~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
lsb_release -a
output:
Description: Ubuntu 20.04.1
LTS Release: 20.04
Codename: focal
whereis python
output:
python: /usr/bin/python3.6 /usr/bin/python3.7 /usr/bin/python2.7-config /usr/bin/python2.7 /usr/bin/python3.6m /usr/bin/python3.9 /usr/bin/python3.8 /usr/bin/python /usr/bin/python3.7m /usr/lib/python3.6 /usr/lib/python3.7 /usr/lib/python2.7 /usr/lib/python3.9 /usr/lib/python3.8 /etc/python3.6 /etc/python3.7 /etc/python2.7 /etc/python3.9 /etc/python3.8 /etc/python /usr/local/lib/python3.6 /usr/local/lib/python3.7 /usr/local/lib/python2.7 /usr/local/lib/python3.9 /usr/local/lib/python3.8 /usr/include/python3.6 /usr/include/python2.7 /usr/include/python3.6m /usr/include/python3.8 /usr/share/python
/etc/apt/sources.list
only contains focal software sources.
also ran
sudo apt update
sudo apt upgrade
removed python3.9, sudo apt install python3.8-venv
fails with the same error
python3.8-venv : Depends: python3.8 (= 3.8.5-1~20.04) but 3.8.6-1+bionic1 is to be installed E: Unable to correct problems, you have held broken packages.
dpkg --get-selections | grep hold
returns empty
dpkg --get-selections
doesn't find any held packages but I'll try the other suggestionspython-venv
package may be having issues getting installed because of that. (just speculating here)