Windows 环境下 Python3 离线安装 cryptography 失败

发布Flask Web项目时,报错缺少Cryptography,于是尝试重新安装该库,但本机没有网络,只支持手动离线安装,尝试了pip、setup.py两种方式安装,结果都报错。。最后使用将安装包拷贝至本机(在其他电脑上安装的sitepackages里面的文件),重启后发现可以读取到该库

报错:RuntimeErrorRuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methodsTraceback (most recent call last)·         File "E:\software\python\lib\site-packages\flask\app.py", line 2213, in __call__return self.wsgi_app(environ, start_response)·         File "E:\software\python\lib\site-packages\flask\app.py", line 2193, in wsgi_appresponse = self.handle_exception(e)·         File "E:\software\python\lib\site-packages\flask\app.py", line 2190, in wsgi_appresponse = self.full_dispatch_request()·         File "E:\software\python\lib\site-packages\flask\app.py", line 1486, in full_dispatch_requestrv = self.handle_user_exception(e)·         File "E:\software\python\lib\site-packages\flask\app.py", line 1484, in full_dispatch_requestrv = self.dispatch_request()·         File "E:\software\python\lib\site-packages\flask\app.py", line 1469, in dispatch_requestreturn self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)·         File "E:\projects\WEB\HR_DL_DATA\hrproject\hrproject\V0809.01\app.py", line 7, in my_echartconn1, cur1 = utils.get_conn()·         File "E:\projects\WEB\HR_DL_DATA\hrproject\hrproject\V0809.01\utils.py", line 8, in get_connconn = pymysql.connect(host='127.0.0.1',·         File "E:\software\python\lib\site-packages\pymysql\connections.py", line 352, in __init__self.connect()·         File "E:\software\python\lib\site-packages\pymysql\connections.py", line 636, in connectself._request_authentication()·         File "E:\software\python\lib\site-packages\pymysql\connections.py", line 933, in _request_authenticationauth_packet = _auth.caching_sha2_password_auth(self, auth_packet)·         File "E:\software\python\lib\site-packages\pymysql\_auth.py", line 265, in caching_sha2_password_authdata = sha2_rsa_encrypt(conn.password, conn.salt, conn.server_public_key)·         File "E:\software\python\lib\site-packages\pymysql\_auth.py", line 143, in sha2_rsa_encryptraise RuntimeError(RuntimeError: 'cryptography' package is required for sha256_password or caching_sha2_password auth methodsThe debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:·   dump() shows all variables in the frame·   dump(obj) dumps all that's known about the object

这个报错提示是由于在您的项目中使用了 pymysql 库,而该库需要依赖 cryptography 来支持 sha256_passwordcaching_sha2_password 身份验证方法。由于您当前的环境中缺少 cryptography 包,所以导致了这个报错。

为了解决这个问题,您可以考虑以下几种方法:

  1. 手动安装 cryptography 包: 尝试手动从源代码构建并安装 cryptography 包,如前面所述。这将为 pymysql 提供所需的支持。

  2. 尝试其他 MySQL 连接库: 如果您只是为了连接 MySQL 数据库,您也可以尝试使用其他的 MySQL 连接库,例如 mysql-connector-python,它可能不需要 cryptography 依赖。

  3. 等待更新: 如前所述,您也可以等待 cryptography 更新并发布适用于您的配置的版本。

无论您选择哪种方法,都需要确保您的项目中安装了所需的依赖库,并且根据需要更新或调整代码以适应新的库版本。

cryptography需要单独安装吗?

是的,cryptography 包需要单独安装。它不是Python的内置标准库,因此需要使用 pip 命令来安装。

您可以使用以下命令来安装 cryptography 包:

pip install cryptography

安装完成后,您的项目应该就能够正常使用 pymysql 库并支持 sha256_passwordcaching_sha2_password 身份验证方法了。这将解决您之前报错的问题。

如果您没有网络连接,无法直接使用 pip 安装 cryptography 包,您可以从另一台有网络连接的计算机上下载 cryptography 包的安装文件(whl 文件),然后将其传输到您的目标计算机进行安装。

以下是具体步骤:

  1. 在有网络连接的计算机上,使用以下命令下载 cryptography 包的安装文件:
pip download cryptography
  1. 这将会下载 cryptography 包及其依赖的安装文件到当前目录。将下载得到的 .whl 文件复制到您的目标计算机上。

  2. 在目标计算机上,使用以下命令进行安装(假设您将 .whl 文件放在了同一个文件夹内):

pip install cryptography-3.3.2-cp36-abi3-win_amd64.whl

请注意,上述命令中的 .whl 文件名可能与您下载的文件名略有不同,您需要根据实际文件名进行调整。

通过这种方式,您可以将 cryptography 包的安装文件从有网络连接的计算机传输到目标计算机上,从而在没有网络连接的情况下进行安装。

我能直接把cryptography、cryptography-3.3.2.dist-info复制到sitepackages吗?

是的,您可以尝试将 cryptography 包及其相关的 .dist-info 文件夹复制到 Python 的 site-packages 目录中。这种方法有时可以在没有网络连接的情况下手动安装包。

请按照以下步骤操作:

  1. 从另一台有网络连接的计算机上下载 cryptography 包的 .whl 安装文件和 .dist-info 文件夹。确保您下载的是适用于您的 Python 版本和操作系统的版本。

  2. 将这些文件复制到目标计算机上。您可以将 cryptography 包的 .whl 文件和 .dist-info 文件夹一起复制到目标计算机上的 Python 的 site-packages 目录中。

  3. 打开命令行窗口,并导航到 Python 安装目录的 Scripts 文件夹中(例如:E:\software\python\Scripts)。

  4. 在命令行中运行以下命令来重新生成安装包的元数据缓存:

    python -m ensurepip
    
  5. 然后,尝试在命令行中运行您的应用程序,看看是否成功解决了报错问题。

请注意,尽管这种方法在某些情况下可能有效,但由于包的版本和依赖性问题,可能并不总是适用。在没有网络连接的情况下手动安装包时,请务必备份好您的现有环境,以防止出现意外问题。

如果这些步骤无法解决问题,可能需要尝试其他方法或在有网络连接的环境中进行操作。

我拷贝了cryptography 包及其相关的 .dist-info 文件夹复制到 Python 的 site-packages 目录中,发现还是读取不到这个包

如果您将cryptography包及其相关的.dist-info文件夹复制到了Python的site-packages目录中,但仍然无法读取该包,您可以尝试以下步骤:

  1. 确保您已经将cryptography包及其.dist-info文件夹复制到了正确的site-packages目录下。您可以通过运行以下命令来查找Python的site-packages路径:

    python -m site
    

    在输出中查找USER_SITEENABLE_USER_SITE行,以确定site-packages的路径。

  2. 确保复制的文件具有正确的权限。有时,文件权限问题可能会影响包的加载。您可以尝试使用管理员权限复制文件,或者确保复制的文件具有与其他包相同的权限。

  3. 确保您的Python解释器版本与您从其他计算机下载的cryptography包的版本相匹配。如果版本不匹配,可能会出现问题。

  4. 在将文件复制到site-packages目录后,尝试重新生成安装包的元数据缓存。在命令行中运行以下命令:

    python -m ensurepip
    
  5. 重新启动您的Python解释器,然后尝试导入cryptography包并运行您的应用程序。

如果您仍然无法解决问题,可能需要考虑其他解决方法,例如尝试使用其他计算机进行安装并将生成的虚拟环境(包括site-packages目录)复制到您的目标计算机上。另外,您还可以考虑在有网络连接的环境中解决此问题,例如使用代理或移动到网络连接较好的地方进行操作。

重启了电脑可以读取到!!!

其他问题

怎么处理这个问题:Microsoft Windows [版本 10.0.17134.1]

© 2018 Microsoft Corporation。保留所有权利。

E:\software\python\Lib\site-packages\package\cr\cryptography-3.3.2>python setup.py install

E:\software\python\lib\site-packages\setuptools_init_.py:84: _DeprecatedInstaller: setuptools.installer and fetch_build_eggs are deprecated.

!!

    ********************************************************************************Requirements should be satisfied by a PEP 517 installer.If you are using pip, you can try `pip install --use-pep517`.********************************************************************************

!!

dist.fetch_build_eggs(dist.setup_requires)

WARNING: The wheel package is not available.

running install

E:\software\python\lib\site-packages\setuptools_distutils\cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.

!!

    ********************************************************************************Please avoid running ``setup.py`` directly.Instead, use pypa/build, pypa/installer, pypa/build orother standards-based tools.See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.********************************************************************************

!!

self.initialize_options()

E:\software\python\lib\site-packages\setuptools_distutils\cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.

!!

    ********************************************************************************Please avoid running ``setup.py`` and ``easy_install``.Instead, use pypa/build, pypa/installer, pypa/build orother standards-based tools.See https://github.com/pypa/setuptools/issues/917 for details.********************************************************************************

!!

self.initialize_options()

running bdist_egg

running egg_info

writing src\cryptography.egg-info\PKG-INFO

writing dependency_links to src\cryptography.egg-info\dependency_links.txt

writing requirements to src\cryptography.egg-info\requires.txt

writing top-level names to src\cryptography.egg-info\top_level.txt

reading manifest file ‘src\cryptography.egg-info\SOURCES.txt’

reading manifest template ‘MANIFEST.in’

no previously-included directories found matching ‘docs_build’

warning: no previously-included files found matching ‘vectors’

warning: no previously-included files matching ‘*’ found under directory ‘vectors’

warning: no previously-included files matching ‘*’ found under directory ‘.github’

warning: no previously-included files found matching ‘release.py’

warning: no previously-included files found matching ‘.coveragerc’

warning: no previously-included files found matching ‘codecov.yml’

warning: no previously-included files found matching ‘.readthedocs.yml’

warning: no previously-included files found matching ‘dev-requirements.txt’

warning: no previously-included files found matching ‘rtd-requirements.txt’

warning: no previously-included files found matching ‘tox.ini’

warning: no previously-included files matching ‘*’ found under directory ‘.zuul.d’

warning: no previously-included files matching ‘*’ found under directory ‘.zuul.playbooks’

adding license file ‘LICENSE’

adding license file ‘LICENSE.APACHE’

adding license file ‘LICENSE.BSD’

adding license file ‘LICENSE.PSF’

adding license file ‘AUTHORS.rst’

writing manifest file ‘src\cryptography.egg-info\SOURCES.txt’

installing library code to build\bdist.win-amd64\egg

running install_lib

running build_py

running build_ext

generating cffi module ‘build\temp.win-amd64-cpython-310\Release\_padding.c’

already up-to-date

generating cffi module ‘build\temp.win-amd64-cpython-310\Release\_openssl.c’

already up-to-date

building ‘_openssl’ extension

=============================DEBUG ASSISTANCE=============================If you are seeing a compilation error please try the following steps tosuccessfully install cryptography:1) Upgrade to the latest pip and try again. This will fix errors for mostusers. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip2) Read https://cryptography.io/en/latest/installation.html for specificinstructions for your platform.3) Check our frequently asked questions for more information:https://cryptography.io/en/latest/faq.html=============================DEBUG ASSISTANCE=============================

error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/

E:\software\python\Lib\site-packages\package\cr\cryptography-3.3.2>

解决办法

问题出在你缺少 Microsoft Visual C++ 14.0 或更高版本的编译工具,这是安装 cryptography 包时出现的错误。为了解决这个问题,你需要安装 Microsoft C++ Build Tools。你可以按照以下步骤进行操作:

  1. 访问链接 https://visualstudio.microsoft.com/visual-cpp-build-tools/,下载并安装 Microsoft Visual C++ 14.0 或更高版本的编译工具。这将为你提供所需的编译环境,使得安装 cryptography 包时能够成功编译相关的 C 扩展。

  2. 安装完成后,重新运行你的安装命令。你可以使用 pip 命令代替 python setup.py install 进行安装,同时添加 --use-pep517 参数,以启用 PEP 517 安装程序:

    pip install . --use-pep517
    
  3. 如果上述步骤无法解决问题,你可以尝试执行以下操作:

    • 确保你的 Python 环境和安装的包是兼容的,例如确保使用的是与 cryptography 包兼容的 Python 版本。
    • 更新你的 pip 版本到最新版本:pip install --upgrade pip
    • 阅读 cryptography 包的官方安装文档,以获取针对你的操作系统和环境的具体安装指导:https://cryptography.io/en/latest/installation.html。

如果你仍然遇到问题,可以尝试在官方文档中提到的“DEBUG ASSISTANCE”部分提供的调试步骤,这可能会帮助你进一步解决安装问题。
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/33941.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计算机网络 网络层 IPv4地址

A类地址第一位固定0 B类10 其下同理

Golang基础教程

Golang基础教程 golang简介安装golanggolang开发工具go常用命令golang开发 vscode快捷键如何编写golang代码golang标识符、关键字、命名规则golang变量go语言常量go语言数据类型go语言布尔类型go语言数字类型golang字符串golang格式化输出golang运算符go语言中的流程控制golan…

hutool 读取每个sheet,数据转成List<Map<>>的格式

1.接收上传的excel文件流,取出第一个sheet ApiOperation("【干部管理】根据excel导入干部和企业")PostMapping("/importExcel")Transactionalpublic Result importExcel(RequestParam MultipartFile file) throws IOException {Logger logger LoggerFact…

22 | 书籍推荐数据分析

import numpy as np import pandas as pd import seaborn as sns import matplotlib.pyplot as plt from sklearn.cluster import KMeans from sklearn import neighbors from sklearn.model_selection import train_test_split from sklearn.preprocessing import

python编辑器安装与配置,python用哪个编辑器好用

大家好,给大家分享一下python编辑器pycharm安装教程,很多人还不知道这一点。下面详细解释一下。现在让我们来看看! 哪些python的编程软件值得推荐? 编写python源代码的软件.首推的Pycharm。 PyCharm用于bai一般IDE具备的功能&…

WordPress中实现层级文章的访问权限继承

这篇文章也可以在我的博客中查看 本文内容 在WordPress中存在层级文章的设定,常见于:Page、Custom Post Type 有时候我们需要让子文章的访问权“继承”于父文章,即: 当父文章为私有、草稿时,子文章也无法被公开访问…

leetcode做题笔记71

给你一个字符串 path ,表示指向某一文件或目录的 Unix 风格 绝对路径 (以 / 开头),请你将其转化为更加简洁的规范路径。 在 Unix 风格的文件系统中,一个点(.)表示当前目录本身;此外…

MacOS安装RabbitMQ

官网地址: RabbitMQ: easy to use, flexible messaging and streaming — RabbitMQ 一、brew安装 brew update #更新一下homebrew brew install rabbitmq #安装rabbitMQ 安装结果: > Caveats > rabbitmq Management Plugin enabled by defa…

字符统计、

描述 给定一篇文章,包含3行文字,每行有80个字符。请编写程序,统计其中的英文大写字母、小写字母、数字、空格以及其他字符的个数。 输入 输入为三行字符串,每行字符串长度不超过 80。 输出 输出五行,分别表示对应…

C++笔记之if(指针)的含义

C笔记之if(指针)的含义 code review! 文章目录 C笔记之if(指针)的含义例1例2 例1 例2

2308C++内存序概略

参考 释放:在释放前的任意读写操作不能放在此操作之后. 获取:在获取后的任意读写操作不能放在此操作之前. 放松:只保证本操作的原子性,一般用于统计. 消费:在加载后的依赖本原子变量的,都不能重排在本操作之前. 获取释放:获取释放 序列一致,完全一致.

基于 CentOS 7 构建 LVS-DR 群集。

1.准备实验环境 本次实验我准备了4台虚拟机 DS:DIP--192.168.163.138 VIP--192.168.163.200 RIP1(web1)--192.168.163.140 RIP2(web2)--192.168.163.141 Client:user--192.168.163.142 2.配置服务器环境 1)搭建简易的web服务 RIP1 [rootlocalhost ~]# yum …

Maven工程的安装配置及搭建(集成eclipse完成案例,保姆级教学)

目录 一.下载及安装及环境配置 1.下载及安装 2.环境变量的配置 3.检测是否安装成功 4.配置Maven 1.更换本地仓库 2. 配置镜像 二.集成eclipse完成案例 1.eclipse前期配置Maven 2.创建Maven工程 一.下载及安装及环境配置 1.下载及安装 下载地址:Maven – Down…

JUL 日志 - 最简单易用的Java日志框架

在正式的生产环境下是不能使用 System.out 进行日志记录的 因为 System.out 不能提供时间、线程、执行过程 等信息,如果要手动打印输出则会非常麻烦 而日志就帮我们把这些事给干了 接下来我们学一个最简单的日志框架 JUL JUL全称Java util Logging是java原生的日志框…

SpringBoot汇总

文章目录 构建SpringBoot项目springboot项目启动后执行一段程序的方式Spring Boot Devtools 开发热部署springboot项目控制台打印sql日志SpringBoot定时任务之ScheduledSpringBoot使用Validation校验参数springboot中,日志的配置和与其他日志的兼容问题springboot错…

MDC轻量化日志链路跟踪的若干种应用场景

0x01 前言 当你的应用程序同时处理多个用户的请求时,你会看到日志文件或者控制台中的输出通常都是交错的,而非线性连续的。尤其是在分布式系统中,一个用户请求可能包含了若干次的服务节点调用,它的日志也因此变得碎片化&#xff…

数据结构:堆的实现(C实现)

个人主页 : 个人主页 个人专栏 : 《数据结构》 《C语言》 文章目录 一、堆二、实现思路1. 结构的定义2. 堆的构建 (HeapInit)3. 堆的销毁 (HeapDestroy)4. 堆的插入 (HeapPush)5. 堆的删除 (HeapPop)6. 取堆顶的数据 (HeapTop)7. 堆的数据个数 (HeapSize…

k8s-1.22.3集群etcd备份与恢复

一、环境准备 注:请在测试环境下验证操作 CentOS Linux release 7.7.1908 (Core) 3.10.0-1062.el7.x86_64 kubeadm-1.22.3-0.x86_64 kubelet-1.22.3-0.x86_64 kubectl-1.22.3-0.x86_64 kubernetes-cni-0.8.7-0.x86_64 主机名IPVIPk8s-master01192.168.10.61192…

Gephi国家政策文本关键词共现矩阵的共现网络图分析

文章目录 分词jieba分词关键词提取python处理形成共现矩阵gephi导入共现矩阵过滤边的权重进行优化最终效果分词 本文研究不同文章中的关键词出现次数,因此将出现在同一篇文章中的关键词都定义为”共现”。 jieba分词 对不同后缀文件(txt、docx、pdf)进行不同处理,提取文…

RK3568开发笔记-Vendor Storage分区使用

目录 前言 一、什么是Vendor Storage分区? 二、Vendor Storage分区使用 总结 前言 在嵌入式系统开发中&#x