您的位置:首页 > 编程语言 > Python开发

windows pip install MySQL-python

2017-07-28 09:47 435 查看
环境,windows64位下,python版本是2.7.11,因为操作数据库需要安装mysql-python,所以直接命令行下,

命令:pip install mysql-python


报错:

_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No s
uch file or directory


error: command 'C:\\Program Files (x86)\\Common Files\\Microsoft\\Visual C++ for
Python\\9.0\\VC\\Bin\\cl.exe' failed with exit status 2


起初以为需要安装VC for python,,,下载后还是不行

后来直接下载源文件mysql for python

命令:python set.py install

还是报错!!!

解决方案:

在这里下载对应文件

http://www.codegood.com/downloads

因为是我 windows64 位 所以MySQL-python-1.2.3.win-amd64-py2.7.exe

其他的在上面链接,按照自己的对应版本下载,双击即可

要想验证一下,可以这样做:

命令行下>>>import MySQLdb
直接打印>>>print MySQLdb
<module 'MySQLdb' from 'C:\Python27\lib\site-packages\MySQLdb\__init__.pyc'>


OK!,收工!!

error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat). Get it from http://aka.ms/vcpython27[/code] 
下载:Microsoft Visual C++ Compiler for Python 2.7

https://www.microsoft.com/en-gb/download/confirmation.aspx?id=44266

python version 2.7 required,which was not found in the registry

安装PIL-1.1.7.win32-py2.7的时候,不能再注册表中识别出来python2.7

方法:新建一个register.py 文件,把一下代码贴进去,保存

#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
# http://www.pythonware.com/products/works/articles/regpy20.htm #
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html 
import sys

from _winreg import *

# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix

regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)

def RegisterPy():
try:
reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
try:
reg = CreateKey(HKEY_CURRENT_USER, regpath)
SetValue(reg, installkey, REG_SZ, installpath)
SetValue(reg, pythonkey, REG_SZ, pythonpath)
CloseKey(reg)
except:
print "*** Unable to register!"
return
print "--- Python", version, "is now registered!"
return
if (QueryValue(reg, installkey) == installpath and
QueryValue(reg, pythonkey) == pythonpath):
CloseKey(reg)
print "=== Python", version, "is already registered!"
return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!"

if __name__ == "__main__":
RegisterPy()


按F5执行即显示:

显示“python 2.7 is already registered”

再安装setuptools的时候,就能自动识别出来python2.7了。

win7是 64的原因,在安装python(32位)时,如果选择只为当前用户,以上问题是不会出现的,如果选择所有用户,那就用上面的方法解决吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: