使用pip install命令安装包时报No matching distribution的错误

在github下载了一份代码,在服务器上执行pip install -r requirements.txt时报如下错误:

ERROR: Could not find a version that satisfies the requirement torch==2.1.2 (from versions: 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.4.0, 1.5.0, 1.5.1, 1.6.0, 1.7.0, 1.7.1, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 1.10.0, 1.10.1, 1.10.2)
ERROR: No matching distribution found for torch==2.1.2
  • 在服务器上,我使用conda create --name envs_name python==3.11.7命令创建了一个新的环境,然而当我执行pip install -r requirements.txt命令时却报以上错误。
  • 于是通过以上报错信息在网上寻找答案,然而基本上都是让我尝试修改pip源,或者降低版本安装。这并没有解决我的问题。
  • 后面我继续尝试使用pip install package命令来安装包,直到有一次报错信息的最下面给出了一条信息:

Requirement already satisfied: pip in /home/jsjx/.local/lib/python3.6/site-packages (21.3.1)

很敏感的看到python3.6与conda环境中的python3.11.7版本不一致,并且pip的版本为21.3.1。于是我尝试使用pip install --upgrade pip升级pip的版本。命令行的结果显示:

/usr/lib/python3/dist-packages/secretstorage/dhcrypto.py:15: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.utils import int_from_bytes
Defaulting to user installation because normal site-packages is not writeable
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pip in /home/jsjx/.local/lib/python3.6/site-packages (21.3.1)

看到这里,我恍然大悟。在我使用pip执行命令时,系统调用的pip指令并不是conda环境中的,而是系统上默认的3.6版本。那我们该如何使用conda环境中的pip呢?

  1. 使用绝对路径:在 conda 环境中,使用绝对路径来调用指定 conda 环境中的 pip。
  2. 重新配置环境变量:检查你的环境变量 PATH,确保 conda 的路径在系统的 PATH 变量中优先级较高。你可以编辑 .bashrc 或 .bash_profile 文件。

在这里,我选用了第一种方法。通过调用/anaconda3/envs/your_env/bin/pip install package_name 成功安装了所需的包。

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值