gpt4 book ai didi

python - 带有 Python 3.6 的 MYSQLdb

转载 作者:行者123 更新时间:2023-11-30 22:05:48 28 4
gpt4 key购买 nike

我很难在 Python 3.6 下安装 MYSQLdb。我已经为此奋斗了大约一天,希望有人能解决这个问题。请注意,如前所述,我正在运行 Windows 10、MY SQL Workbench 6.3、PyCharm 2016.3.2 和 Python 3.6。首先,当尝试在 PyCharm 中执行包含 MYSQLdb 导入的代码时,我会收到一条错误消息,提示未找到模块。所以,我当然尝试 pip install 基本上所有可能的二进制文件。对于大多数情况,我会得到以下信息:

C:\Users\[me]>pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Building wheels for collected packages: mysql-python
Running setup.py bdist_wheel for mysql-python ... error
Complete output from command c:\python36\python.exe -u -c "import
setuptools, tokenize;__file__='C:\\Users\\[me]\\AppData\\Local\\Temp\\pip-build-90yksnqx\\mysql-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d C:\Users\[me]\AppData\Local\Temp\tmprh_xynj1pip-wheel- --python-tag cp36:
running bdist_wheel
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying _mysql_exceptions.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.6\MySQLdb
creating build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.6\MySQLdb\constants
running build_ext
building '_mysql' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python36\include -Ic:\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.6\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(42): fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

Failed building wheel for mysql-python
Running setup.py clean for mysql-python
Failed to build mysql-python
Installing collected packages: mysql-python
Running setup.py install for mysql-python ... error
Complete output from command c:\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\[me]\\AppData\\Local\\Temp\\pip-build-90yksnqx\\mysql-python\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\[me]\AppData\Local\Temp\pip-h7ydssnj-record\install-record.txt --single-version-externally-managed --compile:
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying _mysql_exceptions.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.6\MySQLdb
creating build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.6\MySQLdb\constants
running build_ext
building '_mysql' extension
creating build\temp.win-amd64-3.6
creating build\temp.win-amd64-3.6\Release
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" -Ic:\python36\include -Ic:\python36\include "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\8.1\include\shared" "-IC:\Program Files (x86)\Windows Kits\8.1\include\um" "-IC:\Program Files (x86)\Windows Kits\8.1\include\winrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.6\Release\_mysql.obj /Zl
_mysql.c
_mysql.c(42): fatal error C1083: Cannot open include file: 'config-win.h': No such file or directory
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

因此,我什至尝试安装 3.6 的非官方二进制文件,网址为 http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy

这安装很好,但在 PyCharm 中执行时仍然不走运。

接下来,我进入 PyCharm 中的 preferences=>project interpreter 并尝试直接从那里安装 MYSQLdb。这样,我得到了另一个错误:

Collecting MySQLdb

Could not find a version that satisfies the requirement MySQLdb (from versions: )
No matching distribution found for MySQLdb

根据我的研究,这似乎在使用新版本的 Python 时经常发生。有谁知道解决方法或何时支持 3.6?

最佳答案

尝试使用完全支持许多 ODBC 驱动程序的 sqlalchemy。 Insted 使用 mysqldb,mysqlconnector 在 python3.x 中更好。我将一个项目从 sqlite 迁移到 mysql 服务器并在 python3.6 中工作正常sqlalchemy 提供了一个连接另一个 ODBC 的解决方案。

关于python - 带有 Python 3.6 的 MYSQLdb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41824551/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com