问题
I am trying to use mysql with python SQLAlchemy however python fails to install MySQL or even recognize it is installed. Below are the details:
I'm running this on Windows 10 64 bit and Anaconda Python 3.6.5
I downloaded MySQL through MAMP: Mac-Apace-MySQL-PHP https://www.mamp.info/en/
I have tried running my code on VSC and Jupyter.
If I try running the code
pip install mysqlclient
_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit status 2
I tried
pip install MySQL-python
but get_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\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit status 2
I tried
pip install MySQLdb
and get:Collecting MySQLdb Could not find a version that satisfies the requirement MySQLdb (from versions: ) No matching distribution found for MySQLdb
I tried installing MySQL - from the actual Oracle website, did not work
I tried downloading the MySQL-connector to python: I get python v3.6 not found. we only support python using MSI.
I heave searched this issue on SoF but every issue is either outdated or custom geared towards that poster's case and I honestly would not know where to start. I've read that it may be a config issue to where python can't tell where MySQL is located and so I need to customize the path to it but I do not have the technical depth to meddle with that as I'm worried I may end up making it even worst.
I sincerely appreciate any input to this matter as I am truly in a bind and have no idea where to go from here.
回答1:
Use the precompiled binary whl file from Cristoph Golke. It's far easier than setting up the complete dev environment to compile a single library.
Download the .whl file, then pip install <path to .whl>
inside the python environment you're using.
回答2:
Install the Mysql Connector/C and restart pip install mysqlclient
. If your Visual C is properly installed it will work
回答3:
Maybe you are opening something that uses the python process executing one of files need to be downloaded for installing (in my experience, I was opening Pycharm, and the process was using '_mysql.cp36-win_amd64.pyd' file)
Hope this helps someone
回答4:
None of the solutions here and elsewhere worked for me. Turns out an incompatible 32bit version of mysqlclient is being installed on my 64bit Windows 10 OS.
I had to uninstall my current Python 3.7 32bit, and reinstalled Python 3.7 64bit and everything is working fine now
回答5:
For install mysqlclient you need to Visual C++ 2015 Build Tools. Use below link to download visualstudio tool. http://go.microsoft.com/fwlink/?LinkId=691126&fixForIE=.exe.
Now you need to set your visual studio path in path variable by using below command in commandline.
“setx path "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"”
Now you need to install mysqlclient by using below command “pip install mysqlclient”
If you found error like “MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory error: command 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe' failed with exit status 2”
so you need to download .whl file for direct install, You can use below link to download as per your system compatibility.
“https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient.Then”
“mysqlclient-1.4.2-cp37-cp37m-win32.whl” file work for me.
“pip install mysqlclient-1.4.2-cp37-cp37m-win32.whl”
Mysqlclient is install now!!
You need to change setting.py according to mysql
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'learnpython',
'USER': 'nilesh',
'PASSWORD': 'Radhe@12',
'HOST': 'localhost',
'PORT': 3306
}
}
Enjoy now Django is connect with mysql!! For more details "http://itfundasphp.blogspot.com/2019/06/django-connect-to-mysql.html"
来源:https://stackoverflow.com/questions/51118963/issues-installing-mysqldb-with-python-3-6-5-cant-open-mysql-h-and-cant-op