Virtual Environment Error with Python 3.6.3 - python

I'm not sure why I can't create this virtual environment on my Mac. I get an error on a call to python3 in my environment and when I dig in it seems to be looking for something called ensurepip.
Any idea what I'm doing wrong?
$ python3 -m venv venv_test
Error: Command '['/Users/raysalemi/workspaces/install_mcs_project/venv_test/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
$ /Users/raysalemi/workspaces/install_mcs_project/venv_test/bin/python3 -Im ensurepip --upgrade --default-pip
/Users/raysalemi/workspaces/install_mcs_project/venv_test/bin/python3: No module named ensurepip
$ pip
Usage:
pip <command> [options]

Related

python returned non-zero exit status 1

I try to create a virtual environment to let me install NumPy, SciPy and Matplotlib
I write this: python3.8 -m venv work3.8
and the result was: Error: Command '['/home/mohammed/work3.8/bin/python3.8', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
Probably you got the message because the venv package is not present on your system for python3.8or that you need sudo before the command.
Solve it by installing the venv package for python3.8:
apt install python3.8-venv
Then create a new venv virtual environment:
python3.8 -m venv ~/.venvs/work3.8
The above assumes that inside your home directory, you have previously created a directory called .venv, inside of which the venv virtual environments will be stored. If not, it can be created with mkdir ~/.venv
You might need to prepend sudo to the commands, depending on what privileges your user has, like so:
sudo apt install python3.8-venv
sudo python3.8 -m venv ~/.venvs/work3.8
Please try: python3 -m venv [your directory]
After that, if you want to use your new virtual enviroment type: source [your directory]/bin/activate
Then if you want to leave your venv type: deactivate
(checked on Debian)
I hope that this helps you,
Kind regards

New python 3.6 venv giving error on MacOS

I have a python 3.5.2 anaconda installation on MacOS v10.11.
$ which python
/Users/<username>/anaconda3/bin/python
If I try to run python command to build a virtual env in the same directory
py-venv $ python -m venv /Users/<username>/workarea/py-venv
Error: Command '['/Users/<username>/workarea/py-venv/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
Then it complains with the error mentioned above. The same error occurs if I use the same commands with python3 instead of python.
Any clues?

pyvenv returns non-zero exit status 1 (during the installation of pip stage)

If you should ever encounter the following error when creating a Python virtual environment using the pyvenv command:
user$ pyvenv my_venv_dir
Error: Command '['/home/user/my_venv_dir/bin/python', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
... then the answer (below) provides a simple way to work around it, without resorting to setuptools and it's related acrobatics.
Here's an approach that is fairly O/S agnostic...
Both the pyvenv and python commands themselves include a --without-pip option that enable you to work around this issue; without resorting to setuptool or other headaches. Taking note of my inline comments below, here's how to do it, and is very easy to understand:
user$ pyvenv --without-pip ./pyvenv.d # Create virtual environment this way;
user$ python -m venv --without-pip ./pyvenv.d # --OR-- this newer way. Both work.
user$ source ./pyvenv.d/bin/activate # Now activate this new virtual environment.
(pyvenv.d) user$
# Within it, invoke this well-known script to manually install pip(1) into /pyvenv.d:
(pyvenv.d) user$ curl https://bootstrap.pypa.io/get-pip.py | python
(pyvenv.d) user$ deactivate # Next, reactivate this virtual environment,
user$ source ./pyvenv.d/bin/activate # which will now include the pip(1) command.
(pyvenv.d) user$
(pyvenv.d) user$ which pip # Verify that pip(1) is indeed present.
/path/to/pyvenv.d/bin/pip
(pyvenv.d) user$ pip install --upgrade pip # And finally, upgrade pip(1) itself;
(pyvenv.d) user$ # although it will likely be the
# latest version already.
# And that's it!
I hope this helps. \(◠﹏◠)/
2020, on python3.8 on WSL2 (Ubuntu) the following solved this for me:
sudo apt install python3.8-venv
If you have a module whose file is named after a python standard library, in the folder on which you invoke python -m venv venv, then this command will fail without a hint about that.
For instance, you name a file email.py.
What I did to find this was coding a bash script which moves the .py files off the current directory one by one (to a holdspace/ subdir), and try at each move to invoke the venv dir creation. If the python -m venv venv command exits with 0 code, so it's successful and the last file moved was the culprit.
#!/bin/bash
if [ ! -d ./holdspace ]
then
mkdir holdspace/
fi
for file in *.py
do
mv "$file" holdspace/
python -m venv venv >/dev/null 2>&1
if [ $? -eq 0 ]
then
echo "$file was the culprit."
rm -rf venv/
break
else
echo "$file isn't the culprit."
fi
rm -rf venv/
done
mv holdspace/*.py .
The following should fix it
brew update
brew upgrade
brew install zlib

Tox Invocation Error while trying to run command 'sudo tox'

While working in an virtualenv [3.4] I was trying to run tox for running the tests when I got the error:
py34 develop-inst-nodeps: /home/horcrux/dir-sub/dir
py34 runtests: commands[0] | python -m nose2 -v
/home/horcrux/dir-sub/dir/.tox/py34/bin/python: No module named nose2
ERROR: InvocationError: '/home/horcrux/dir-sub/dir/.tox/py34/bin/python -m nose2 -v'
_____________________________ summary ______________________________________
ERROR: py34: commands failed
I've already tried to install nose2 using pip install nose2 but still the problem remains the same.
sudo clears the environment. You have to invoke the virtualenv inside of the sudo execution environment. Try:
sudo bash -c ". [venv/bin/activate] ; [tox]"
Replace [venv/bin/activate] with the path to your virtualenv activate script and replace [tox] with whatever command you are using to invoke it.

venv doesn't create activate script python3

When trying to create a virtulenv using venv with python 3 on ubuntu it isn’t creating an activate script. It conitunally exits with an error 1.
Following docs and other posts on SO such as https://stackoverflow.com/a/19848770
I have tried creating it 2 different ways.
sayth#sayth-TravelMate-5740G:~/scripts$ python3 -m venv test4
Error: Command '['/home/sayth/scripts/test4/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth#sayth-TravelMate-5740G:~/scripts$ source test4/bin/activate
bash: test4/bin/activate: No such file or directory
sayth#sayth-TravelMate-5740G:~/scripts$ ls test4/bin/
python python3
or
sayth#sayth-TravelMate-5740G:~/scripts$ pyvenv-3.4 test5
Error: Command '['/home/sayth/scripts/test5/bin/python3.4', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth#sayth-TravelMate-5740G:~/scripts$ ls test5/bin/
python python3 python3.4
How can I get it to fully create a venv?
If I do it as below with stil no success unsure what the issue is?
sayth#sayth-TravelMate-5740G:~/scripts$ python3 -Im venv panda3
Error: Command '['/home/sayth/scripts/panda3/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
sayth#sayth-TravelMate-5740G:~/scripts$ python3 -m venv panda4
Error: Command '['/home/sayth/scripts/panda4/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
Looks like you are using Ubuntu 14.04. It was shipped with a broken pyvenv. There is a simple work around to create venv using Python 3
1. Create venv without pip
python3 -m venv --without-pip test4
or
pyvenv-3.4 --without-pip test4
2. Get pip in your env
source test4/bin/activate
curl https://bootstrap.pypa.io/get-pip.py | python
deactivate
source test4/bin/activate
or
pyvenv-3.4 --without-pip myvenv
source ./myvenv/bin/activate
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-3.4.4.tar.gz
tar -vzxf setuptools-3.4.4.tar.gz
cd setuptools-3.4.4
python setup.py install
cd ..
wget https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz
tar -vzxf pip-1.5.6.tar.gz
cd pip-1.5.6
python setup.py install
cd ..
deactivate
source ./myvenv/bin/activate
Source: HackerNews, AskUbuntu
Anaconda involucred.
If you are using Anaconda or Miniconda this solution may help:
Conda manages python itself as a package, so that conda update python is possible, in contrast to pip, which only manages Python packages. Conda is available in Anaconda and Miniconda (an easy-to-install download with just Python and conda).
So, this command would help:
conda update python
very disturbing for me but well, hands to the keyboard in a terminal window: (click here, see the picture)
Thanks for your attention, have a nice day!
The command:
python3 -m virtualenv env
works for me, whereas:
python3 -m venv env
does not.
This worked for me:
python3 -m venv --without-pip test4
Once I typed that in the terminal, the "test4" venv was created. And the 'activate' script was also created in the 'bin' directory.
To anyone using python3, having trouble with this, just substitute the name of the directory you want to create for "test4" (or rename it later).
That should do it.

Categories

Resources