python多版本py命令及虚拟环境管理

创建虚拟环境失败, 已经很久没有用python3这个命令,可能又被系统环境修改的时候弄乱了.花点时间整理下

$ python3 -m venv ./venv

Error: Command ‘[‘E:\code\venv\Scripts\python.exe’, ‘-Im’, ‘ensurepip’, ‘–upgrade’, ‘–default-pip’ returned non-zero exit status 1.

把从windows store 下载的python3.8版本给卸了, 从官网下载python3.11

使用py 替代 python命令

默认py命令创建虚拟环境
$ py -m venv venv
进入vscode
& e:/code/venv/Scripts/Activate.ps1
$ pip3 install -r requirements.txt -i https://mirrors.ustc.edu.cn/pypi/web/simple/

ERROR: Ignored the following versions that require a different python version: 1.21.2 Requires-Python >=3.7,<3.11; 1.21.3
Requires-Python >=3.7,<3.11; 1.21.4 Requires-Python >=3.7,<3.11; 1.21.5 Requires-Python >=3.7,<3.11; 1.21.6 Requires-Python >=3.7,<3.11; 1.6.2 Requires-Python >=3.7,<3.10; 1.6.3 Requires-Python >=3.7,<3.10; 1.7.0 Requires-Python >=3.7,<3.10; 1.7.0rc1 Requires-Python >=3.7,<3.10; 1.7.0rc2 Requires-Python >=3.7,<3.10; 1.7.1 Requires-Python >=3.7,<3.10; 1.7.2 Requires-Python >=3.7,<3.11; 1.7.3 Requires-Python >=3.7,<3.11; 1.8.0 Requires-Python >=3.8,<3.11; 1.8.0rc1 Requires-Python >=3.8,<3.11; 1.8.0rc2 Requires-Python >=3.8,<3.11; 1.8.0rc3 Requires-Python >=3.8,<3.11; 1.8.0rc4 Requires-Python >=3.8,<3.11;
1.8.1 Requires-Python >=3.8,<3.11
ERROR: Could not find a version that satisfies the requirement torch>=1.7.0 (from versions: none)
ERROR: No matching distribution found for torch>=1.7.0

又从官网下了python3.9

$ py --list
-V:3.11 *        Python 3.11 (64-bit)
-V:3.9           Python 3.9 (64-bit)
-V:3.6-32        Python 3.6 (32-bit)# win10系统自带的.无法卸载
-V:2.7 # 老项目使用,这个环境不能动

py指定python版本,生成虚拟环境,目录下文件名为venv
$ py -3.9 -m venv venv
进入vscode

win
$ & e:/code/venv/Scripts/Activate.ps1
mac
$ source ./venv/bin/activate

退出

$ deactivate

$ pip3 install -r requirements.txt -i https://mirrors.ustc.edu.cn/pypi/web/simple/

正常完成requirements下载

centos安装python3.9

wget https://www.python.org/ftp/python/3.9.6/Python-3.9.6.tgz

tar -xf Python-3.9.6.tgz

cd Python-3.9.6

./configure 或者 ./configure –enable-optimizations
问题: https://blog.csdn.net/hd243608836/article/details/121418565
make altinstall
注意使用altinstall而不是install,以避免覆盖系统默认的Python版本。
python3.9 –version
Python 3.9.6

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2023年9月8日
下一篇 2023年9月8日

相关推荐