Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyvenv not working because ensurepip is not available

People also ask

How do I enable virtual environment in Python?

To use the virtual environment you created to run Python scripts, simply invoke Python from the command line in the context where you activated it. For instance, to run a script, just run python myscript.py .


try installing python3.6-venv:

sudo apt-get install python3.6-venv

It seems that it was a locale problem. Solved by executing:

export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
sudo dpkg-reconfigure locales

found on this thread Python locale error: unsupported locale setting


One of the other answers fixed it for me last time, but with Python 3.7 I had to do:

apt install python3-pip python3-setuptools python3.7-venv

Followed by

python3.7 -m venv /path/to/venv

Under Windows Linux Subsystem and Ubuntu 18.04, this was caused by my not having upgraded recently.

I ran:

sudo apt update
sudo apt upgrade

Then sudo apt install python3-venv worked.

Note that I had also tried the UTF-8 solution beforehand (I made it part of my .bashrc), so that could have been a contributing factor.


Resolved similar problems on Ubuntu18 when came upon this answer. It is similar to the one that worked for @Niko Rikken, except it doesn't really need any new PPA's and "python3.8-distutils" package. I was installing new python3.8 environment with venv and I already had "python3-venv" installed and up to date, so my solution was to install only "python3.8-venv":

% sudo apt-get install python3.8-venv

And that got this lines working:

% python3.8 -m venv ~/envs/new_env
% source ~/envs/new_env/bin/activate

In my case the next steps worked:

  • Ubuntu 18.04.4 LTS
 $ sudo apt-get install python3-venv python3.7-venv
 $ python3.7 -m venv [your_path_to_virtual_env_here]

In case this helps anyone down the line, I was getting the same error on Ubuntu 18.04. Setting the locales didn't work and trying to install python3-venv gave the error:

$ 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.6-venv (>= 3.6.5-2~) but it is not going to be installed
                Depends: python3 (= 3.6.5-3) but 3.6.7-1~18.04 is to be installed
E: Unable to correct problems, you have held broken packages.

And it looks like the apt repository had two versions of python:

$ apt list python3 -a
python3/bionic-updates,now 3.6.7-1~18.04 amd64 [installed]
python3/bionic 3.6.5-3 amd64

I tried to install Python3.6.5-3 but apt wanted to uninstall every dependency. I was able to solve the problem by installing Python3.7 and creating the venv with that:

$ sudo apt-get install python3.7 python3.7-venv
$ python3.7 -m venv my_venv