今天配置一个环境的包的时候,使用requirements.txt文件时遇到几个问题,记录一下,执行以下代码
pip install -r requirements.txt
要注意该文件的路径,可以把完整路径写入,这样避免报错找不到该文件
其次,在执行上述指令的时候,发生了类似如下的错误,而且在虚拟环境中找不到“我以为的安装好的包”,这是因为,在按照requirements.txt文件安装的时候,是按照先后顺序来的,如果有一个错误整个下载都会终止 ,所以一定要注意文件中的版本号是否正确
ERROR: Ignored the following versions that require a different python version: 1.16.0rc1 Requires-Python >=3.11; 1.6.2 Requires-Python >=3.7,<3.1
0; 1.6.3 Requires-Python >=3.7,<3.10; 1.7.0 Requires-Python >=3.7,<3.10; 1.7.1 Requires-Python >=3.7,<3.10; 2.3.0rc1 Requires-Python >=3.11; 3.5r
c0 Requires-Python >=3.11
ERROR: Could not find a version that satisfies the requirement torch==2.1.2+cu121 (from versions: 1.11.0, 1.12.0, 1.12.1, 1.13.0, 1.13.1, 2.0.0,
2.0.1, 2.1.0, 2.1.1, 2.1.2, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.4.0, 2.4.1, 2.5.0, 2.5.1, 2.6.0, 2.7.0)
ERROR: No matching distribution found for torch==2.1.2+cu121
为了下载的更快,我们可以选择在后边加上镜像地址,如:
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn
最后成功的界面: