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

9

50

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.

Rampart answered 16/10, 2021 at 8:51 Comment(0)
C
102

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"

Crocidolite answered 3/4, 2022 at 13:33 Comment(0)
T
14

I am using windows 10 WSL2 ubuntu 20.04, sudo resolved my problem.

sudo python3.8 -m venv venv
Tacheometer answered 14/12, 2021 at 7:4 Comment(6)
Wow, I've been pulling my hair out for the last 3 hours trying to figure this out and never thought to try sudo.. Needless to say this worked me for me.Screwed
"sudo python3 -m venv my_env" this also works for WSL, Kali linux.Cerelly
That's awesome! I literally had root enabled, but when I use sudo it's worked like magic. I really wonder why is that. (I'm not running Linux inside windows)Strop
using sudo to create a basic virtual env. what the heckOntogeny
I know we shouldn’t use sudo on everything, but it does work in this situation. I didn’t find any other solution.Tacheometer
my guess is it is not because it requires elevated privileges, its more likely because the first user references an alias that is set. root (the user when you use sudo) has it's own .bashrc file and therefore it's own understanding of what the command means. All of that to say, if you don't want to have to use sudo for this command, try comparing your user .bashrc (or .bash_aliases) files with the root.Windward
N
5

Simply i run this virtualenv venv

Because i installed the venv like this pip install virtualenv

Narvaez answered 4/5, 2023 at 12:14 Comment(0)
M
3

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".

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>
Mellisa answered 16/10, 2021 at 9:5 Comment(3)
So what is the cause of the problem and how come install for all users fixes it?Hebrews
That I don't know, reinstalling things usually fixes a lot of issues.Mellisa
Reinstalled, pasted this line: .\python -m venv c:\temp\venv-py38, and the same error showed upRampart
C
3

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>
Cornelie answered 17/10, 2021 at 11:55 Comment(0)
P
2

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.

Pasturage answered 2/1, 2023 at 16:9 Comment(3)
Thank you! This worked for me under cygwin in Windows 10.Mim
seriously, just curious, with the advent of WSL and WSL2, why is anyone still using cygwin??Drabble
Last time I tried WSL was heavier and slower on startup time and did not integrate into Windows as good as Cygwin does - at least for me and my workflow. Unfortunately it's been some time and I don't remember the details. (One minor point was the lack of support for USB Serial adapters.)Pasturage
V
1

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
View answered 11/2, 2023 at 12:28 Comment(0)
F
0

Solution: Removed Some files to make some space available for venv.

OS: Windows

If Cause is: No Space available in the drive

Summary:

In my case, the cause of this error is that No Space is available in the drive (in which I'm creating a virtual environment).

Faithfaithful answered 20/6, 2024 at 3:59 Comment(0)
B
-1

Error: Command '['C:\Users\admin\env\Scripts\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.

This error sometimes occurs because of the antivirus, you can solve it by simply disabling it when using the command.

Bourgeoisie answered 2/4, 2023 at 5:50 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Vaginectomy

© 2022 - 2025 — McMap. All rights reserved.