'pip3 is unable to create virtual environment on Ubuntu 20.04 LTS on Windows 10 because ensurepip is not available
I was working with virtual environments with Ubuntu 18.04 LTS but I uninstalled it and installed Ubuntu 20.04 LTS on windows 10, but now when I create venv
then error is
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.
when I install sudo apt-get install python3-venv
it say installed but still struggling badly
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-venv is already the newest version (3.8.2-0ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Solution 1:[1]
I had the same issue on Ubuntu 20.04 WSL2 Win10 build 2004, when trying to make virtual environment on D:\ drive which is /mnt/d [NTFS]. I was able to solve it with below commands by unmounting and remounting with metadata
sudo umount /mnt/d
sudo mount -t drvfs D: /mnt/d -o metadata
Solution 2:[2]
I found a solution to this problem: The mounted drive I was creating the venv directory in was owned by root. If you think this might be the cause, try creating a venv in your Ubuntu LTS home directory. You should be able to create it there.
From within my project's directory, I ended up using chown recursively with this command:
sudo chown --from=root:root -R myname:myname *
Note that you might not want to do this on the whole drive, so be careful where you do this with recursive commands.
Here are the basic instructions for setting up a brand new Python 3.8 environment, except right before I made the venv, I made sure to be the owner of the directory:
Note: A more correct way of doing it might be to change the mounting options of drives using the wsl.conf instructions here, but it didn't seem to help when I tried: https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/
Other things I did before I stumbled upon this:
- I tried un/reinstalling "Ubuntu 20.04 LTS" and with the digitalocean steps above was able to reproduce the errors you had verbatim.
- I also uninstalled the Microsoft Store app named "Ubuntu 20.04 LTS" and reinstalled the one simply labeled "Ubuntu". It probably didn't make a difference because both options install build 20200423 of Ubuntu 20.04 LTS.
Other notes for Python 3.8 in Ubuntu 20.04, for problems I experienced directly after activating my new venv which might not apply to you:
- You might need to
pip install wheel
so that commands likepip install jupyter
do not have errors.
Solution 3:[3]
After going through Phy6's Answer, I just tried running it as sudo and it worked.
$ sudo python3 -m venv venv
Solution 4:[4]
I'm a bit late, By default, 20.0.4 ships with python3.8
if you're specifically looking to install virtualenv for other version's, try installing the version and retry.
eg: for python3.6
sudo apt-get install python3.6
and to create a virutalenv
python3.6 -m venv venv_name
Solution 5:[5]
For me, this issue happened because I was trying to create a virtual environment using another virtual environment. "venv-ception"
I solved by:
- Deactivating the venv
- Then creating a new venv
i.e.
# 1. deactivate the venv
deactivate
# 2. create and activate your new venv
mkdir .venv
python3 -m venv .venv
source .venv/bin/activate
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Prabath |
Solution 2 | PHY6 |
Solution 3 | Craziest Hacker |
Solution 4 | Dharman |
Solution 5 | wjkw1 |