Cannot find activate file in Python venv in Linux - python

I am trying to install venv but getting this error:
name#malikov:~/Desktop/informtech$ python3 -m venv venv
Error: Command '['/home/name/Desktop/informtech/venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
venv folder created but there is no activate file to activate venv
What should I do. Is there any solution. All problems started after upgrading python version from 3.8 to 3.10strong text

You can try installing venv for python3.10 via command:
sudo apt install python3.10-venv

Related

Error when creating venv, Error: Command '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

When I try to create venv it throws this error:
Error: Command '['C:\\Users\\admin\\env\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
It is strange for me because I'm using python for a long time and never had such a problem.
On Ubuntu first, install the venv of the specific python version
sudo apt install python3.9-venv
python3.9 -m venv myenv //specify the python version. This will create the virtual env "myenv"
I am using windows 10 WSL2 ubuntu 20.04, sudo resolved my problem.
sudo python3.8 -m venv venv
1- head over this doc and try to refix your global python installation accordingly, don't forget to check Install launcher for all users option, after successful installation the py launcher will be localed under C:\Windows folder.
2- use isolated vrtual environement, venv built-in module is recommended over other 3rd tools and just avoid to mess with your global python folder.
PS c:\YOUR_PROJECT_FOLDER> py --version
PS c:\YOUR_PROJECT_FOLDER> py -0p # many python version (3.8.x, 3.9.X, 3.10.x ..) can co-exist without any conflict
PS c:\YOUR_PROJECT_FOLDER> py -m venv venv
PS c:\YOUR_PROJECT_FOLDER> .\venv\Scripts\activate
(venv) PS c:\YOUR_PROJECT_FOLDER> pip list
Package Version
---------- -------
pip 20.2.3
setuptools 49.2.1
WARNING: You are using pip version 20.2.3; however, version 21.3 is available.
You should consider upgrading via the 'c:\users\USER\desktop\YOUR_PROJECT_FOLDER\venv\scripts\python.exe -m pip install --upgrade pip' command.
# Here just copy/past that link to update the local pip of your virtual environment
(venv) PS c:\YOUR_PROJECT_FOLDER> c:\users\USER\desktop\YOUR_PROJECT_FOLDER\venv\scripts\python.exe -m pip install --upgrade pip
Collecting pip
Using cached pip-21.3-py3-none-any.whl (1.7 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 20.2.3
Uninstalling pip-20.2.3:
Successfully uninstalled pip-20.2.3
Successfully installed pip-21.3
(venv) PS c:\YOUR_PROJECT_FOLDER> pip list
Package Version
---------- -------
pip 21.3
setuptools 49.2.1
(venv) PS c:\YOUR_PROJECT_FOLDER> pip install <PYTHON_PACKAGE>
This has something to do with the Windows update.
PS C:\Users\Your Name\AppData\Local\Programs\Python\Python38> ./python -m venv c:\TEMP\py38-venv
Error: Command '['c:\\TEMP\\py38-venv\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 101.
This will fix the issue:
Uninstall Python.
Install with the Custom option.
Use the "Install for all users".
After this it worked fine:
PS C:\Utilities\PythonBase\Python38> .\python -m venv c:\temp\venv-py38
PS C:\Utilities\PythonBase\Python38>
TLDR: On Cygwin install python-setuptools-wheel and python-pip-wheel packages.
To find the specific reason I installed a venv without pip support first (python3 -m venv venv --without-pip) loaded it and ran the failing command (python -Im ensurepip --upgrade --default-pip) manually. This generated a stack trace suggesting that it iterates over all versions of the setuptools wheel but none is actually installed:
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 188, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.9/runpy.py", line 147, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.9/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python3.9/ensurepip/__init__.py", line 30, in <module>
_SETUPTOOLS_VERSION = _get_most_recent_wheel_version("setuptools")
File "/usr/lib/python3.9/ensurepip/__init__.py", line 27, in _get_most_recent_wheel_version
return str(max(_wheels[pkg], key=distutils.version.LooseVersion))
ValueError: max() arg is an empty sequence
After installing python-setuptools-wheel it generates the same stack trace but with _get_most_recent_wheel_version("pip") -- hence python-setuptools-pip is also missing. After installing that as well the command works and generating a venv with pip support also works.
In order to create a virtual environment, Python requires some packaging tools to be installed. The packaging tools are found in python3-setuptools.
Installing the Python3 setup tools should correct this error.
sudo apt install python3-setuptools

Ensurepip module not existing, how to install manually?

In the interest of not getting an XY problem: the goal is to create a virtual environment on synology dsm, so no apt-get, where pip is installed manually.
I am trying to create a virtual environment, in above environment (synology dsm package python 3.8 with pip installed manually).
However this gives the following error:
$ python3 -m venv new_venv
Error: Command '['/volume1/docker/builder/new_venv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
In the chain of finding that error I discovered that venv is working "just fine":
$ python3 -m venv --without-pip new_venv
Works as expected. Also pip itself works as expected. However I had to install pip manually. This also has as consequence that the synology dsm version of python does not have the module ensurepip..
# python3 -c "import ensurepip; print(ensurepip.__file__);"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'ensurepip'
This gives the problem: how does one manually install ensurepip, and/or make virtual env install pip without relying on ensurepip?
Install pip inside your venv virtual environment
Download the newest pip installation script and name the file get-pip.py:
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Create the virtual environment with Python 3 but without pip inside it (assuming you are in /volume1/docker/builder/):
$ python3 -m venv --without-pip /volume1/docker/builder/new_venv
Activate the virtual environment:
$ source /volume1/docker/builder/new_venv/bin/activate
Your prompt should now contain the virtual environment name in parens:
(new_venv) $
The script will install pip inside the activated venv virtual environment:
(new_venv) $ python get-pip.py
# or
(new_venv) $ python3 get-pip.py

Cannot create virtual environment with pip in it / Cannot run python in Virtual Environment

Python: 3.7
Windows 10, 64-bit
Error with creating virtual environment of python using
python -m venv envname
Error: python', '-im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1
(Environment is created but there is no pip and very few scripts in which there is python, but cannot be accessed)
And when made without pip
python -m venv --without-pip envname
Pip cannot be installed while activating environment and executing the following command in it (curl https://bootstrap.pypa.io/get-pip.py | python)
Error: Unable to create process using '<python.exe path>'

Can't create a python virtual environment on Ubuntu 18.04

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

How to create virtualenv with python 3.6 venv

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.

Categories