麻烦安装mysql python,在django中找不到mysqldb模块 [英] trouble installing mysql python, mysqldb module not found in django
问题描述
我第一次将mysql
与django
一起使用.两者都已安装,我可以在工作台或命令提示符中使用mysql
,但是当我尝试在django
中进行迁移时,它找不到mysqldb
模块,将其切掉了大部分,请参见下文:
I'm using mysql
with django
for the first time. Both are installed, I can use mysql
in the workbench or command prompt, however when I tried migrations in django
, it can't find the mysqldb
module, cut most of it out, see below:
回溯(最近通话最近一次):
Traceback (most recent call last):
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-connector
,annaconda
,并尝试了关于此和Google的许多其他建议,但不走运.它给了我下面的错误:
So i've been trying to use pip install mysql-python
and can't do it. I've installed mysql-connector
, annaconda
, and tried many other suggestions on this and google, no luck. It gives me the error below:
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
Nothing i've done or tried has worked, any suggestions? i'm using windows10
更新,我终于能够安装pip mysql-python,现在遇到的唯一错误是我尝试进行迁移时没有名为mysqldb的模块. mysql-connector,已安装mysqlclient,仍然没有运气.
Update, I finally was able to get pip mysql-python installed, now the only error I get is the no module named mysqldb when I try to makemigrations. mysql-connector, mysqlclient is installed, still no luck.
推荐答案
有时 pip install mysqlclient 命令不起作用 因此,请按照以下步骤操作:
sometimes pip install mysqlclient command doesn't work so follow these steps:
1)搜索非官方python二进制文件或 转到 https://www.lfd.uci.edu/~gohlke/pythonlibs/ 并在该页面上搜索(ctrl + f)mysqlclient
1) search unofficial python binaries or go to https://www.lfd.uci.edu/~gohlke/pythonlibs/ and search(ctrl+f)on that page for mysqlclient
2)在计算机上检查您的python版本 并下载适用于您下载的python版本的 whl 文件 喜欢 在命令提示符下键入python 你会得到你的python版本
2) check your python version on machine and download the whl file appropriate for your downloaded python version like type python in command prompt and you will get your python version
>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安装mysqlclient-1.4.4-cp37-cp37m-win32.whl
3) download that file and type following code in your environment or where you downloaded the whl file >pip install mysqlclient-1.4.4-cp37-cp37m-win32.whl
希望这会起作用
这篇关于麻烦安装mysql python,在django中找不到mysqldb模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!