Reputation: 4314
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
or
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
and
sudo apt-get install python3.5-venv
but it did not solve my problem.
Upvotes: 189
Views: 230949
Reputation: 2697
try installing python3.6-venv:
sudo apt-get install python3.6-venv
Or the latest venv available for your system python
sudo apt-get install python3-venv
Upvotes: 233
Reputation: 149
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
Upvotes: 7
Reputation: 14835
The solution for installing python3-venv is accurate since debian/ubuntu split the python distribution across multiple packages, so you do not actually have a full python install. If you really do not want to install this apt package, here is an alternative
python3 -m pip install virtualenv
virtualenv .venv
This will create fully functioning venv.
Upvotes: 2
Reputation:
I had to mention the specific version of python
and replace python3.10 with you version
$ sudo apt-get update -y && sudo apt-get upgrade -y
$ sudo apt-get install python3.10-venv
Creating a virtual environment
$ python3.10 -m venv --system-site-packages Project_Name
Upvotes: 8
Reputation: 901
I do not have sudo rights and I have to use python3.5:
I did 'source <path>/bin/activate' and I got a working environment.
Upvotes: 0
Reputation: 117
mkdir testing
cd testing
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
sudo apt install python3.8-venv
python3 -m venv bhandari
Note: you can named this "bhandari" folder; anyname you like( Standard practice is to name it "env" ...)
source bhandari/bin/activate
After this, we can install anything that will be isolated from the rest of the system....
Upvotes: 6
Reputation: 1763
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
.
Upvotes: 0
Reputation: 8055
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
Upvotes: 1
Reputation: 2442
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.
Upvotes: 1
Reputation: 476
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
Upvotes: 1
Reputation: 41
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>
sys.exit(ensurepip._main())
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
hare/python-wheels/pyparsing-2.4.7-py2.py3-none-any.whl']
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.
Upvotes: 3
Reputation: 879
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
Upvotes: 13
Reputation: 571
Try installing python3-distutils
as well.
Altogether,
for python 3.8, the following worked for me.
$ apt-get install python3.8 python3.8-venv python3.8-distutils python3.8-dev
Upvotes: 3
Reputation: 87201
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.
Upvotes: 0
Reputation: 547
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
Upvotes: 5
Reputation: 11
This worked for me... Firstly, I ran
sudo apt-get update
Then
sudo apt-get install -y python3-venv zip
Upvotes: 1
Reputation: 1
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
Upvotes: -2
Reputation: 121
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
Upvotes: 5
Reputation: 2604
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.
Edit:
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.
Upvotes: 9
Reputation: 45
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)'
Upvotes: 0
Reputation: 69
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
Upvotes: 1
Reputation: 171
In my case the next steps worked:
$ sudo apt-get install python3-venv python3.7-venv
$ python3.7 -m venv [your_path_to_virtual_env_here]
Upvotes: 11
Reputation: 329
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.
Upvotes: 0
Reputation: 3191
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 packagepython3.8 -m venv venv
source venv/bin/activate
python --version
# -> python 3.8.0pip --version
# -> pip 9.0.1 from /home/user/venv/lib/python3.8/site-packages (python 3.8)Upvotes: 3
Reputation: 1611
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. :-D
Upvotes: -1
Reputation: 197
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.)
Upvotes: 1
Reputation: 3156
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
Upvotes: 9
Reputation: 41
Try : python3.* -m venv myvenv -
And don't forget to replace * with your specific version of python
Upvotes: 4
Reputation: 6811
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.
Upvotes: 95
Reputation: 1165
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
Upvotes: 62