创建 venv 时出错,错误:命令 '-Im'、'ensurepip'、'--u

2023-06-05Python开发问题
441

本文介绍了创建 venv 时出错,错误:命令 '-Im'、'ensurepip'、'--upgrade'、'--default-pip']' 返回非零退出状态 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当我尝试创建 venv 时,它会抛出此错误:

When I try to create venv it throws this error:

错误:命令 '['C:\Users\admin\env\Scripts\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' 返回非零退出状态 1.

我很奇怪,因为我用python很久了,从来没有遇到过这样的问题.

It is strange for me because I'm using python for a long time and never had such a problem.

推荐答案

1- 顶一下 doc 并尝试相应地修复您的全局 python 安装,不要忘记检查 Install launcher for all users 选项,成功安装后 py 启动器 将本地化在 C:Windows 文件夹下.

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- 使用隔离的虚拟环境,venv 内置模块比其他第三个工具更推荐,避免弄乱你的全局 python 文件夹.

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> .venvScriptsactivate
(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:usersUSERdesktopYOUR_PROJECT_FOLDERvenvscriptspython.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:usersUSERdesktopYOUR_PROJECT_FOLDERvenvscriptspython.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>

这篇关于创建 venv 时出错,错误:命令 '-Im'、'ensurepip'、'--upgrade'、'--default-pip']' 返回非零退出状态 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11