使用Python 3.6的MYSQLdb

使用Python 3.6的MYSQLdb,python,mysql,pycharm,Python,Mysql,Pycharm,在Python3.6下安装MYSQLdb非常困难。我已经为此奋斗了大约一天,希望有人能解决这个问题。注意,正如前面提到的,我正在运行Windows 10、SQL Workbench 6.3、PyCharm 2016.3.2和Python 3.6。首先,当尝试在PyCharm中执行包含MYSQLdb导入的代码时,我会得到一个错误,表示找不到模块。所以,我当然尝试了pip安装基本上所有可能的二进制文件。对于大多数人来说,我会得到以下信息: C:\Users\[me]>pip install m

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

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版的非官方二进制文件,可在

这安装得很好,但在PyCharm中执行时仍然没有运气

接下来,我进入PyCharm中的preferences=>project解释器,并尝试直接从那里安装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。与使用mysqldb不同,mysqlconnector在python3.x中更好。我将一个项目从sqlite迁移到mysql服务器,并在python3.6中运行良好
sqlalchemy提供了一种连接另一个ODBC的解决方案。

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

我也遇到了同样的问题

我按照另一个答案的建议,使用下面的pip获得了SQLAlchemy:

pip install SQLAlchemy
我一直无法玩它,但它没有错误地安装,所以这里是希望

我也有同样的问题

我按照另一个答案的建议,使用下面的pip获得了SQLAlchemy:

pip install SQLAlchemy

我一直无法玩它,但它没有错误地安装,所以这里是希望

我以前遇到过这个问题,我发现在使用python 3.6时,只需安装mysqlclient: 1-创建一个文件夹,而不是一个virtualenv(virtualenv myvenv--python python3) 2-安装所需的django版本(pip Install django==1.9.3) 3-安装mysqlclient(pip安装mysqlclient)
如果您进入myvenv文件夹/lib/python3.6/site-packages,您将看到MySQLdb模块将在那里。

我以前遇到过这个问题,我发现在使用python 3.6时,您只需要安装mysqlclient: 1-创建一个文件夹,而不是一个virtualenv(virtualenv myvenv--python python3) 2-安装所需的django版本(pip Install django==1.9.3) 3-安装mysqlclient(pip安装mysqlclient) 如果您进入myvenv文件夹/lib/python3.6/site-packages,您将看到MySQLdb模块将在那里。

请参考此处请参考此处