【问题标题】:unable to install cryptography==3.4.7 in venv in python无法在 python 的 venv 中安装 cryptography==3.4.7
【发布时间】:2021-04-27 16:23:01
【问题描述】:

我正在尝试在非互联网机器上安装几个 python 包。得到错误

Could not find a version that satisfies the requirement cryptography==3.4.7 (from -r requirements.txt (line 14)) (from versions: )
No matching distribution found for cryptography==3.4.7 (from -r requirements.txt (line 14))

我下载了在线系统中的所有软件包并将requirements.txt和下载的软件包文件夹移动到离线系统并尝试使用以下命令在那里安装软件包,

pip3.6 install --no-index --find-links="./tranferred_packages" -r requirements.txt

我遵循的步骤 -

  1. 使用 pip 在线安装virtualenv
pip install virtualenv --user

  1. 创建 virtualenv 并获取它
python -m virtualenv myenv
cd myenv 
source bin/activate
  1. 使用安装的包
pip3 install pkgname
  1. 然后做了
pip freeze > requirements.txt
  1. 将 pkgs 下载到一个文件夹中使用
pip download -r requirements.txt
  1. 已将requirements.txt 移动并下载 pkgs 文件夹到离线系统,并尝试使用在那里安装 pkgs
pip install --no-index --find-links="./tranferred_packages" -r requirements.txt

详细错误是

Collecting cryptography==3.4.7 (from -r requirements.txt (line 14))
  0 location(s) to search for versions of cryptography:
  Could not find a version that satisfies the requirement cryptography==3.4.7 (from -r requirements.txt (line 14)) (from versions: )
Cleaning up...
  Removing source in /tmp/pip-build-beg7uvpz/aws-requests-auth
  Removing source in /tmp/pip-build-beg7uvpz/blist
  Removing source in /tmp/pip-build-beg7uvpz/chardet2
No matching distribution found for cryptography==3.4.7 (from -r requirements.txt (line 14))
Exception information:
Traceback (most recent call last):
  File "/root/venv/lib64/python3.6/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/root/venv/lib64/python3.6/site-packages/pip/commands/install.py", line 346, in run
    requirement_set.prepare_files(finder)
  File "/root/venv/lib64/python3.6/site-packages/pip/req/req_set.py", line 381, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/root/venv/lib64/python3.6/site-packages/pip/req/req_set.py", line 557, in _prepare_file
    require_hashes
  File "/root/venv/lib64/python3.6/site-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/root/venv/lib64/python3.6/site-packages/pip/index.py", line 514, in find_requirement
    'No matching distribution found for %s' % req
pip.exceptions.DistributionNotFound: No matching distribution found for cryptography==3.4.7 (from -r requirements.txt (line 14))

requirements.txt 中提到的 cryptographycryptography-3.4.7-cp36-abi3-manylinux2014_x86_64.whl 存在于 tranferred_packages 文件夹中。

cat requirements.txt | grep cryptography
cryptography==3.4.7

(venv) [root@ip-172-35-10-19 venv]# ls -l tranferred_packages/cryptography-3.4.7-cp36-abi3-manylinux2014_x86_64.whl 
-rwxr-xr-x. 1 root root 3181242 Apr 27 15:05 tranferred_packages/cryptography-3.4.7-cp36-abi3-manylinux2014_x86_64.whl
(venv) [root@ip-172-35-10-19 venv]# 

其他没有报错的包的输出,

Collecting certifi==2020.4.5.1 (from -r requirements.txt (line 7))
  0 location(s) to search for versions of certifi:
  Found link file:///root/venv/tranferred_packages/certifi-2020.4.5.1-py2.py3-none-any.whl, version: 2020.4.5.1
  Local files found: /root/venv/tranferred_packages/certifi-2020.4.5.1-py2.py3-none-any.whl
  Using version 2020.4.5.1 (newest of versions: 2020.4.5.1)

我可以在创建 virtualenv 时安装它,但在创建 venv 时不能安装。

使用以下命令创建 virtualenv

pip3 install virtualenv --user

pip3 list的输出

# pip3 list |grep cryptography
cryptography          3.4.7

在这个virtualenv中,python和pip版本是,

python                    python2.7                 python3.6                 python3.6m                python3.6m-x86_64-config  
python2                   python3                   python3.6-config          python3.6m-config         python3-config       

# python -V
Python 3.6.8

# python3.6 -V
Python 3.6.8

pip      pip3     pip-3    pip-3.6  pip3.6

# pip-3.6  -V
pip 21.0.1 from /root/oldenv/lib/python3.6/site-packages/pip (python 3.6)

以上所有 pip 都显示版本为pip 21.0.1,除了pip-3 显示版本为,

pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

创建virtualenv后默认安装以下三个模块

pip 21.0.1
setuptools 56.0.0
wheel 0.34.2

使用以下命令创建 venv

# python3.6 -m venv devenv 

创建venv后默认安装以下两个模块,

pip (9.0.3)
setuptools (39.2.0)

系统范围的 python 和 pip 版本

python                    python2.7                 python3.6                 python3.6m                python3.6m-x86_64-config  
python2                   python3                   python3.6-config          python3.6m-config         python3-config 

# python --version
Python 2.7.5

# python3.6 --version
Python 3.6.8


pip3     pip-3    pip-3.6  pip3.6

# pip3.6  -V
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

其他细节-

RHEL 7.8(迈坡)
内核 - 3.10.0-1127.el7.x86_64

有人可以说是什么导致了问题吗?

谢谢,

【问题讨论】:

  • 当目录transferred_packages 包含cryptography==3.4.7 的轮文件时,pip install --no-index --find-links="./transferred_packages" -r requirements.txt 行在我的系统上有效。此结果是使用virtualenv==20.0.35 (virtualenv is something different than venv) 创建的virtualenv 中的pip==21.1setuptools==56.0.0python==3.9.0+。也许在每个命令之前运行which namename 替换为pippython 等)会有所帮助。
  • 嗨 Loannis,感谢您的回复。如上所述,即使我能够在使用 virtualenv 时安装密码学,但在尝试使用 venv 时会出错。我正在尝试 venv,因为 redhat 建议它在 virtualenv developers.redhat.com/blog/2018/08/13/install-python3-rhel 上使用

标签: python python-3.x pip virtualenv


【解决方案1】:

使用python3 -m pip install --upgrade pip-21.1-py3-none-any.whl 命令从pip-9.0.3 升级到pip-21.1 (pip-21.1-py3-none-any.whl) 后问题得到解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    • 2014-11-23
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多