I upgraded from ubuntu 14.04 to ubuntu 16.04 a few days ago.
When I try to create a virtual env by using

pyvenv .venv


python3 -m venv .venv

There is an error:

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/user/.venv/bin/python3.5', '-Im', 'ensurepip', '--upgrade', '--default-pip']

I tried running both

sudo apt-get install python3-venv


sudo apt-get install python3.5-venv

but it did not solve my problem.

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

I encountered this problem on Ubuntu 18.04 for the recent release of Python-3.8. My solution was to add the Deadsnakes PPA which supplies the required python3.8-distutils package. The python3.8-venv package is already in the repository. Thanks to this blogpost:

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.8
sudo apt install python3.8-distutils
sudo apt install python3.8-venv

Note: This is only a temporary solution. In the near future the required python3.8-distutils package will probably be available in the default Ubuntu repository.


For Ubuntu 20.04 LTS the python3-distutils package is based on Python 3.8. As of yet there is no Python 3.8 package distutils package available for Ubuntu 18.04 LTS.

As mentioned in other comments on this thread, distutils might not be required. It was for my use-case, but please consider that solution before adding additional PPA’s.

  1. First, make a directory :
mkdir testing
  1. Then, moved to this directory named testing :
cd testing
  1. When you type following command in this directory:
python3 -m venv env

You got error like :

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 install python3.8-venv
  1. Type the following command but before that keep an eye on the version of python you installed on the machine; in my case its python3.8
sudo apt install python3.8-venv
  1. Now, we can create a virtual environment and store its tools in the “bhandari” folder .
python3 -m venv bhandari   

Note: you can named this “bhandari” folder; anyname you like( Standard practice is to name it “env” …)

  1. Now to activate your virtual environment, from the directory of your folder, type the following command this will activate our virtual environment in the “bhandari” folder
source bhandari/bin/activate
  1. If you have successfully activated your virtual environment, you should see the (bhandari) word indicating that we are working in a virtual environment.

After this, we can install anything that will be isolated from the rest of the system….

Try the following commands:

sudo apt install python-virtualenv
virtualenv --python=python3.6 myenv

These commands might work for you.

If you get any error like E: Unable to locate package python3-venv
Then try the following commands:

sudo apt install python3.6-venv

Python updated or Default python changed and venv already installed

the venv installed on your system is installed by your previous python version(let say python3.6). that’s why venv is not working with current python version(lets say 3.8).

so first check your default python or python3 version,( suppose ur current version is python3.8).

reinstall virtual environment by mentioning current python version(3.8) as follow

sudo apt-get install python3.xx-venv        >> replace xx with your current/default python version

if this helps you plz upvote, I’m new on this platform.

Try : python3.* -m venv myvenv -

And don’t forget to replace * with your specific version of python

I was faced with the same problem and I am searching for a solution. It is about the problem:

ensurepip is disabled in Debian/Ubuntu for the system python.

And this my solution:

python3 -m venv myvenv --without-pip --system-site-packages

If your intention was to get python3.8 incl. pip and venv on Ubuntu 18.04:

  • sudo apt install python3.8 python3.8-venv python3-pip # there is no python3.8-pip package
  • python3.8 -m venv venv
  • source venv/bin/activate
  • python --version # -> python 3.8.0
  • pip --version # -> pip 9.0.1 from /home/user/venv/lib/python3.8/site-packages (python 3.8)

Try installing python3-distutils as well.
for python 3.8, the following worked for me.

$ apt-get install python3.8 python3.8-venv python3.8-distutils python3.8-dev

I had the same problem – the python env has 2 versions for 2.7 and 3.6.

All you need to do is:

  1. Install the latest version of pip by installing pyenv installer
  2. Make sure you follow the steps of installing pyenv found here

Good Luck!

I had the same problem for an existing project when executing python3 -m venv venv. I had just updated my Ubuntu and Python versions. After removing the already existing venv folder the issue was solved. (I have also tried the UTF-8 solution.)

My problem were related to permissions and ownership.
I was logged in with a different user as the owner of the current directory, which led to this error.
After reviewing and fixing all permissions I was able to install the venv regularl

I just ran across this issue on several Debian/Ubuntu systems. Same error as above.


I tried to create a venv manually with:

python -m venv venvdir

This failed in the same way as others have mentioned. But it did create the shell of the venv. So I tried running ensurepip:

venvdir/bin/python -m ensurepip

Traceback (most recent call last):
    File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main                       
        return _run_code(code, main_globals, None,                                             
    File "/usr/lib/python3.9/runpy.py", line 87, in _run_code                                  
        exec(code, run_globals)                                                                
    File "/usr/lib/python3.9/ensurepip/__main__.py", line 5, in <module>                       
    File "/usr/lib/python3.9/ensurepip/__init__.py", line 266, in _main                        
        return _bootstrap(                                                                     
    File "/usr/lib/python3.9/ensurepip/__init__.py", line 166, in _bootstrap                  
         copy_wheels(dependencies, venv_wheel_dir, sys.path)                                    
    File "/usr/lib/python3.9/ensurepip/__init__.py", line 144, in copy_wheels                  
        assert len(wheel_names) == 1, wheel_names                                            

AssertionError: ['/usr/share/python-wheels/pyparsing-2.2.0-py2.py3-none-any.whl', '/usr/s

This seemed odd. A quick look into /usr/share/python-wheels/ revealed – indeed – multiple versions of the same wheel as the error suggests. I have no clue why ensurepip is also ensuring that it only finds one wheel file, go figure.


A check of dpkg -S /usr/share/python-wheels indicated that the python-pip-whl package is the source of those files. This appears to be true for both Ubuntu and Debian.

So, I did:

cd /usr/share
sudo mv python-wheels python-wheels.old
sudo apt reinstall python-pip-whl

And it worked – no more errors. There are no longer duplicates in /usr/share/python-wheels

Absolutely no clue how there were duplicates or why ensurepip is so sensitive to duplicates there… Probably a package upgrade gone wrong somewhere.

All of these suggestions didn’t help me.

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

So I did: sudo apt-get install python3/bionic

Now I have python 3.6.5 and apt-list showed a better list:
$ apt list python3 -a
python3/bionic 3.6.5-3 amd64

With sudo apt-get install python3-venv/bionic I could install pythno3-venv and everything worked.

In my case, running sudo apt-get install python3.8-venv succeeds but it shows the same error when running python3 -m venv .venv.

Finally, this command works out without changing locale.

python3.8 -c 'import venv; venv.create(".venv", with_pip=True)'

This worked for me…
Firstly, I ran

sudo apt-get update


sudo apt-get install -y python3-venv zip

Here is my answer for Ubuntu 14.04. I was able to make venv and pip work with various Python versions. Details:

  • 3.4: Ubuntu 14.04 has Python 3.4 (as package python3.4 etc.). It works:

    $ sudo apt-get install python3.4 python3.4-dev python3.4-venv gcc libc6-dev
    $ mkdir /tmp/try3.4
    $ python3.4 -m venv /tmp/try3.4
    $ . /tmp/try/bin/activate
    (try3.4) $ pip install print-hello-world
    (try3.4) $ print-hello-world
    Hello World!

    If python3.4-venv is removed from the apt-get install command above, then python3.4 -m venv displays the same error message as in the question. However, the error message mentions apt-get install python3-venv to solve it, but that doesn’t work, there is no such package. (The correct package name is python3.4-venv.)

    Please note that Python 3.4 is fairly old, and some Python packages available in PyPI (via pip) don’t work with it.

  • 3.5: It can be installed from the deadsnakes repository. It works:

    $ sudo add-apt-repository ppa:deadsnakes/ppa
    $ sudo apt-get update
    $ sudo apt-get install python3.5 python3.5-dev python3.5-venv gcc libc6-dev
    $ mkdir /tmp/try3.5
    $ python3.5 -m venv /tmp/try
    $ . /tmp/try/bin/activate
    (try3.5) $ pip install print-hello-world
    (try3.5) $ print-hello-world
    Hello World!
  • 3.6: Ditto, it can be installed from the deadsnakes repository. It works:

    $ sudo add-apt-repository ppa:deadsnakes/ppa
    $ sudo apt-get update
    $ sudo apt-get install python3.6 python3.6-dev python3.6-venv gcc libc6-dev
    $ mkdir /tmp/try3.6
    $ python3.6 -m venv /tmp/try3.6
    $ . /tmp/try3.6/bin/activate
    (try3.6) $ pip install print-hello-world
    (try3.6) $ print-hello-world
    Hello World!
  • 3.7: It doesn’t work, because pip install fails with import _ssl, and python3.7 in the deadsnakes repo doesn’t have that module, because Ubuntu 14.04 ships with on old version of OpenSSL which Python 3.7 doesn’t support. See more details in this bug.

  • 3.8–: No Ubuntu 14.04 package for these Python versions in the Ubuntu or deadsnakes repositories.

Ran into the same issue recently. None of the solutions mentioned above worked for me. I eventually get it to working by installing pip3.

apt-get install python3-pip

# then run
python3.8 -m venv env

If you came across this issue while trying to run python -m build to build a python package, this means there probabaly is a syntax issue in your setup.cfg or setup.py file that causes an error creating the temporary venv required for installing dependencies.

Using pip wheels . will give you a less misleading error message.

For Linux, it is not installed by default you have to install venv

// at first check python version
python --version

// install 
sudo apt update
sudo apt install python3.8-venv
sudo apt install python3.8-distutils

// create new env
python3 -m venv project-name
source project-name/bin/activate

In my case, the command failed because I was still in a virtual env but did not notice it very quickly.

If it is the case, try calling deactivate.

I do not have sudo rights and I have to use python3.5:

  1. Install virtualenv: pip3 virtualenv
  2. Create virtualenv without pip: python3 -m venv –without-pip <path>
  3. Downloaded the proper pip bootstrap: https://bootstrap.pypa.io/pip/3.5/get-pip.py
  4. Run: <path>/bin/python3 get-pip.py

I did ‘source <path>/bin/activate’ and I got a working environment.

sudo apt-get update 

Worked for me.

Edit: I would love to know what exactly what was the issue, but I don’t know. I tried running commands as described by the questioner and it was giving error then I updated and it worked. 😀

None of this worked for me.
I am using ubuntu 18.04.
Just uninstalled anaconda completely and everything worked. Posted just in case it helps anyone.
For commands to uninstall: https://linuxize.com/post/how-to-install-anaconda-on-ubuntu-18-04/

rm -rf ~/anaconda3
export PATH="/home/linuxize/anaconda3/bin:$PATH" 
rm -rf ~/.condarc ~/.conda ~/.continuum