无法在django中安装mysqlclient



我在django框架中使用最新的python 3.11版本,为此我需要安装mysqlclient。但是当我尝试安装

时出现错误
pip install mysqlclient 

输出如下错误:

Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [23 lines of output]

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
/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
error: subprocess-exited-with-error
× Running setup.py install for mysqlclient did not run successfully.
│ exit code: 1
╰─> [25 lines of output]
running install
C:UsersdsemaPycharmProjectsstockvenvLibsite-packagessetuptoolscommandinstall.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated.
Use build and pip and other standards-based tools.
warnings.warn(
running build_ext
building 'MySQLdb._mysql' extension
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
/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> mysqlclient
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

有什么办法可以解决吗?

您显然是在Windows上,所以您希望确保pip尝试使用mysqlclient的二进制包,而不是尝试从头构建一个:

pip install mysqlclient --only-binary=mysqlclient

但是,这可能会安装较旧版本的mysqlclient,因为您正在使用的32位Python 3.11没有二进制包。如果您的机器能够运行64位版本,我强烈建议您改用64位版本,因为在不久的将来,对32位的支持可能会越来越少。

最新更新