I'm a complete beginner to Ubuntu and I'm trying to create a virtual environment on Ubuntu 18.04. I had one running and it was working just fine, but I don't know what I did and know I cant get it to run.
I deleted my old env/ file and now I'm trying to create a new one using
python3 -m venv env
but I get the following error
Error: Command '['/home/user/app/env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit s
tatus 1.
What gives?
Do you have the python3-venv package installed?
If not - install it with apt-get install python3-venv and try again python3 -m venv env
just reinstall your python3-venv
apt-get purge python3-venv
apt-get install python3-venv
and then create the virtualenv
python3.7 -m venv venvTest
if you have different version of python3, you should mention the exact python3 version.
you can also migrate your python3.6 to python3.7 by following guide migrate python3.6 to python3.7
Related
I'm trying to set up a standard virtual-environment(venv) with python 3.7 on Ubuntu 18.04, with pip (or some way to install packages in the venv). The standard way to install python3.7 seems to be:
% sudo apt install python3.7 python3.7-venv
% python3.7 -m venv py37-venv
but the second command fails, saying:
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: ['/py37-venv/bin/python3.7', '-Im', 'ensurepip',
'--upgrade', '--default-pip']
This is true; there is no ensurepip nor pip installed with this python. And I did install python3.7-venv already (python3-venv is for python3.6 on Debian/Ubuntu). I gather there has been some discussion about this in the python community because of multiple python versions and/or requiring root access, and alternate ways to install python modules via apt or similar.
Creating a venv without pip (--without-pip) succeeds, but then there's no way to install packages in the new venv which seems to largely defeat the purpose.
So what's the accepted "best practice" way to install and use python3.7 on 18.04 with a venv?
I don't know if it's best practices or not, but if I also install python3-venv and python3.7-venv then everything works (this is tested on a fresh stock Debian buster docker image):
% sudo apt install python3.7 python3-venv python3.7-venv
% python3.7 -m venv py37-venv
% . py37-venv/bin/activate
(py37-venv) %
Note that it also installs all of python3.6 needlessly, so I can't exactly say I like it, but at least it does work and doesn't require running an unsigned script the way get-pip.py does.
sudo apt install python3-venv
python3 -m venv env
Using snap I installed python38 on an Ubuntu 18 server. now I want to create a new virtual environment but I fail as these commands fail:
virtualenv --python /snap/bin/python38 myvenv
Running virtualenv with interpreter /snap/bin/python38
python3.8: can't open file '/usr/lib/python3/dist-packages/virtualenv.py': [Errno 2] No such file or directory
test -f /usr/lib/python3/dist-packages/virtualenv.py; echo "it exists!"
# OUTPUT: it exists!
# --------------------------------------------------------------------------------
python38 -m venv myvenv
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: ['/tmp/myvenv/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']
This is my first experience with snap, and I'm unsure how I can install python3-venv to make it work.
Any help would be appreciated
I want to create a venv having python3.8 as python3
On Ubuntu 18.04
I did:
> sudo apt install python3.8 python3.8-venv
Now, when I try:
> python3.8 -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/pushp/vizio-backend/env/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']
My application depends on python3.8. What am I missing here?
Resolved, what I did? :
apt install python3.8 python3.8-venv python3-venv
Dont know how but installing both the venv packages python3.8-venv python3-venv resolved it from me. Now when I do:
python3.8 -m venv env
source env/bin/activate
python3 --version
> Python 3.8.0
first:
sudo pip3 install virtualenv
then cd to the directory where you want your virtual environment to be:
virtualenv "name of env" for ex: sudo virtualenv myProject-env
then to activate:
sudo source myProject-env/bin/activate
to make sure that it is work:
sudo which python
Installing python3-distutils also works around the problem.
You might miss the virtual environment installation in your machine.
You can install virtualenv using the following command,
sudo apt-get install python3.8-venv python3-venv
or
python3 -m pip install virtualenv
Referring this document from digitalOcean i got the same error but here in this linein this image change python3.6 to python3.8 then it will work fine.
change python3.6 -m venv my_env to python3.8 -m venv my_env
How to install virtualenv properly on AWS Ubuntu 18.04 AMI. I have tried various ways such as through pip and through apt-get but I am not able to either properly install or configure it. Whenever I am running command virtualenv --python=python3.6 .venv or virtualenv --version it is giving me this error:
ERROR:root:failed to read config file /home/ubuntu/.config/virtualenv/virtualenv.ini because PermissionError(13, 'Permission denied')
How to properly install and configure virtualenv?
First check if Python3 is installed
apt list installed | grep -i python3
After that
python3 -m venv my_app/env
I'm trying to create a python virtualenv using anaconda python3.6 in ubuntu 16.04. Following https://docs.python.org/3/library/venv.html , I've tried
deploy#server:~/miniconda3/bin$ python3 -m venv ~/test
Error: Command '['/home/deploy/test/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
operating from the miniconda directory at ~/miniconda3/bin (screenshot). How can I this working?
edit:
deploy#server:~/miniconda3/bin$ /home/deploy/test/bin/python3 -Im ensurepip --upgrade --default-pip
/home/deploy/test/bin/python3: No module named ensurepip
If you are using anaconda, you should be using conda environments.
conda create --name test
For more information, see Managing Environments.
EDIT In response to OP wanting to use virtualenvs.
The error is with python not being able to find pip. You can get around this by installing it manually.
python3 -m venv test --without-pip
cd test
source bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python3
At this point you will have a basic virtualenv with pip installed.