广州国外建站模板,石家庄公司网站如何制作,泉州企业做网站,重庆建设招标网站发布Flask Web项目时#xff0c;报错缺少Cryptography#xff0c;于是尝试重新安装该库#xff0c;但本机没有网络#xff0c;只支持手动离线安装#xff0c;尝试了pip、setup.py两种方式安装#xff0c;结果都报错。。最后使用将安装包拷贝至本机(在其他电脑上安装的sit…发布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(host127.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 thats known about the object这个报错提示是由于在您的项目中使用了 pymysql 库而该库需要依赖 cryptography 来支持 sha256_password 或 caching_sha2_password 身份验证方法。由于您当前的环境中缺少 cryptography 包所以导致了这个报错。
为了解决这个问题您可以考虑以下几种方法 手动安装 cryptography 包 尝试手动从源代码构建并安装 cryptography 包如前面所述。这将为 pymysql 提供所需的支持。 尝试其他 MySQL 连接库 如果您只是为了连接 MySQL 数据库您也可以尝试使用其他的 MySQL 连接库例如 mysql-connector-python它可能不需要 cryptography 依赖。 等待更新 如前所述您也可以等待 cryptography 更新并发布适用于您的配置的版本。
无论您选择哪种方法都需要确保您的项目中安装了所需的依赖库并且根据需要更新或调整代码以适应新的库版本。
cryptography需要单独安装吗?
是的cryptography 包需要单独安装。它不是Python的内置标准库因此需要使用 pip 命令来安装。
您可以使用以下命令来安装 cryptography 包
pip install cryptography安装完成后您的项目应该就能够正常使用 pymysql 库并支持 sha256_password 或 caching_sha2_password 身份验证方法了。这将解决您之前报错的问题。
如果您没有网络连接无法直接使用 pip 安装 cryptography 包您可以从另一台有网络连接的计算机上下载 cryptography 包的安装文件whl 文件然后将其传输到您的目标计算机进行安装。
以下是具体步骤
在有网络连接的计算机上使用以下命令下载 cryptography 包的安装文件
pip download cryptography这将会下载 cryptography 包及其依赖的安装文件到当前目录。将下载得到的 .whl 文件复制到您的目标计算机上。 在目标计算机上使用以下命令进行安装假设您将 .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 目录中。这种方法有时可以在没有网络连接的情况下手动安装包。
请按照以下步骤操作 从另一台有网络连接的计算机上下载 cryptography 包的 .whl 安装文件和 .dist-info 文件夹。确保您下载的是适用于您的 Python 版本和操作系统的版本。 将这些文件复制到目标计算机上。您可以将 cryptography 包的 .whl 文件和 .dist-info 文件夹一起复制到目标计算机上的 Python 的 site-packages 目录中。 打开命令行窗口并导航到 Python 安装目录的 Scripts 文件夹中例如E:\software\python\Scripts。 在命令行中运行以下命令来重新生成安装包的元数据缓存 python -m ensurepip然后尝试在命令行中运行您的应用程序看看是否成功解决了报错问题。
请注意尽管这种方法在某些情况下可能有效但由于包的版本和依赖性问题可能并不总是适用。在没有网络连接的情况下手动安装包时请务必备份好您的现有环境以防止出现意外问题。
如果这些步骤无法解决问题可能需要尝试其他方法或在有网络连接的环境中进行操作。
我拷贝了cryptography 包及其相关的 .dist-info 文件夹复制到 Python 的 site-packages 目录中发现还是读取不到这个包
如果您将cryptography包及其相关的.dist-info文件夹复制到了Python的site-packages目录中但仍然无法读取该包您可以尝试以下步骤 确保您已经将cryptography包及其.dist-info文件夹复制到了正确的site-packages目录下。您可以通过运行以下命令来查找Python的site-packages路径 python -m site在输出中查找USER_SITE和ENABLE_USER_SITE行以确定site-packages的路径。 确保复制的文件具有正确的权限。有时文件权限问题可能会影响包的加载。您可以尝试使用管理员权限复制文件或者确保复制的文件具有与其他包相同的权限。 确保您的Python解释器版本与您从其他计算机下载的cryptography包的版本相匹配。如果版本不匹配可能会出现问题。 在将文件复制到site-packages目录后尝试重新生成安装包的元数据缓存。在命令行中运行以下命令 python -m ensurepip重新启动您的Python解释器然后尝试导入cryptography包并运行您的应用程序。
如果您仍然无法解决问题可能需要考虑其他解决方法例如尝试使用其他计算机进行安装并将生成的虚拟环境包括site-packages目录复制到您的目标计算机上。另外您还可以考虑在有网络连接的环境中解决此问题例如使用代理或移动到网络连接较好的地方进行操作。
重启了电脑可以读取到
其他问题
怎么处理这个问题Microsoft Windows [版本 10.0.17134.1]
© 2018 Microsoft Corporation。保留所有权利。
E:\software\python\Lib\site-packages\package\cr\cryptography-3.3.2python 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 ASSISTANCEIf 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.htmlDEBUG ASSISTANCEerror: 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。你可以按照以下步骤进行操作 访问链接 https://visualstudio.microsoft.com/visual-cpp-build-tools/下载并安装 Microsoft Visual C 14.0 或更高版本的编译工具。这将为你提供所需的编译环境使得安装 cryptography 包时能够成功编译相关的 C 扩展。 安装完成后重新运行你的安装命令。你可以使用 pip 命令代替 python setup.py install 进行安装同时添加 --use-pep517 参数以启用 PEP 517 安装程序 pip install . --use-pep517如果上述步骤无法解决问题你可以尝试执行以下操作 确保你的 Python 环境和安装的包是兼容的例如确保使用的是与 cryptography 包兼容的 Python 版本。更新你的 pip 版本到最新版本pip install --upgrade pip。阅读 cryptography 包的官方安装文档以获取针对你的操作系统和环境的具体安装指导https://cryptography.io/en/latest/installation.html。
如果你仍然遇到问题可以尝试在官方文档中提到的“DEBUG ASSISTANCE”部分提供的调试步骤这可能会帮助你进一步解决安装问题。