【问题标题】:trouble installing mysql python, mysqldb module not found in django安装mysql python时遇到问题,在django中找不到mysqldb模块
【发布时间】:2017-07-07 14:19:01
【问题描述】:

我第一次使用mysqldjango。两者都已安装,我可以在工作台或命令提示符中使用mysql,但是当我尝试在django 中迁移时,它找不到mysqldb 模块,将其大部分删除,见下文:

Traceback(最近一次调用最后一次):

File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)

File "C:\Users\jerro\Desktop\djangoEnv\lib\site-packages\django\db\backends\mysql\base.py", line 28, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

所以我一直在尝试使用pip install mysql-python,但做不到。我已经安装了mysql-connectorannaconda,并尝试了很多其他关于这个和谷歌的建议,但运气不好。它给了我以下错误:

running build_ext
building '_mysql' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
C:\Users\jerro\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -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:\Python27\include -Ic:\users\jerro\desktop\djangoenv\PC /Tc_mysql.c /Fobuild\temp.win-amd64-2.7\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:\\Users\\jerro\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64\\cl.exe' failed with exit status 2

----------------------------------------


Command "c:\users\jerro\desktop\djangoenv\scripts\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\jerro\\appdata\\local\\temp\\pip-build-_da1js\\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\jerro\appdata\local\temp\pip-kqvwr3-record\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\jerro\desktop\djangoenv\include\site\python2.7\MySQL-python" failed with error code 1 in c:\users\jerro\appdata\local\temp\pip-build-_da1js\MySQL-python\

我做过或尝试过的任何事情都没有奏效,有什么建议吗?我用的是windows10


更新,我终于能够安装 pip mysql-python,现在我得到的唯一错误是当我尝试 makemigrations 时没有名为 mysqldb 的模块。 mysql-connector,mysqlclient已经安装,还是不行。

【问题讨论】:

    标签: mysql django windows python-2.7 pip


    【解决方案1】:

    有时 pip install mysqlclient 命令不起作用 所以请按照以下步骤操作:

    1) 搜索非官方的 python 二进制文件或 转到 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 并在该页面上搜索(ctrl+f)mysqlclient

    2) 在机器上检查你的 python 版本 并下载适合您下载的 python 版本的 whl 文件 喜欢 在命令提示符下输入 python 你会得到你的python版本

    >python
    Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    
    this is python 3.7.3 version and works on 32 bit    
    
    so the whl file will be mysqlclient-1.4.4-cp37-cp37m-win32.whl
    python 3.7.3 = cp37 and 32 bit is win32
    

    3) 下载该文件并在您的环境或您下载 whl 文件的位置键入以下代码 >pip install mysqlclient-1.4.4-cp37-cp37m-win32.whl

    希望这会奏效

    【讨论】:

    • 为我工作,而不是安装 VS buildtools。
    【解决方案2】:

    前往Mysql 并安装连接器。这应该可以解决您的问题。

    【讨论】:

    • 还是什么都没有,我之前已经 pip install mysql-connector 但是那个和这个都没有任何好处。
    猜你喜欢
    • 2019-02-23
    • 2012-04-30
    • 2011-03-15
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    • 2011-08-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多