問題描述
當我嘗試創建 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!