Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
安装MySQL python时出错_Python_Mysql_Pip - Fatal编程技术网

安装MySQL python时出错

安装MySQL python时出错,python,mysql,pip,Python,Mysql,Pip,我正在使用Python 2.7和Django 1.9.4。我想将Django应用程序与MySQL 5.7数据库集成,我执行了: pip install MySQL-python 在Windows 7计算机上使用64位 和获取错误: F:\Djangoproject\mysite>pip install MySQL-python Collecting MySQL-python Using cached MySQL-python-1.2.5.zip Building wheels

我正在使用Python 2.7和Django 1.9.4。我想将Django应用程序与MySQL 5.7数据库集成,我执行了:

pip install MySQL-python
在Windows 7计算机上使用64位

和获取错误:

    F:\Djangoproject\mysite>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:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\chandra\\appdata\\local\\temp\\pip-build
-3qbbxo\\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\chandra\appdata\local\temp\tmpoytuplpip-wheel- --python-tag cp27:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-2.7
  copying _mysql_exceptions.py -> build\lib.win32-2.7
  creating build\lib.win32-2.7\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\release.py -> build\lib.win32-2.7\MySQLdb
  copying MySQLdb\times.py -> build\lib.win32-2.7\MySQLdb
  creating build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\REFRESH.py -> build\lib.win32-2.7\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win32-2.7\MySQLdb\constants
  running build_ext
  building '_mysql' extension
  creating build\temp.win32-2.7
  creating build\temp.win32-2.7\Release
  C:\Users\Chandra\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\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:\python27\PC /Tc_mys
ql.c /Fobuild\temp.win32-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\\Chandra\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit statu
s 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:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\chandra\\appdata\\local\\temp\\pip-bui
ld-3qbbxo\\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\chandra\appdata\local\temp\pip-rskyc7-record\install-record.txt --single-version-externally-managed --compile:

    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-2.7
    copying _mysql_exceptions.py -> build\lib.win32-2.7
    creating build\lib.win32-2.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-2.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-2.7\MySQLdb
    creating build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\REFRESH.py -> build\lib.win32-2.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-2.7\MySQLdb\constants
    running build_ext
    building '_mysql' extension
    creating build\temp.win32-2.7
    creating build\temp.win32-2.7\Release
    C:\Users\Chandra\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -Dversion_in
fo=(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:\python27\PC /Tc_m
ysql.c /Fobuild\temp.win32-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\\Chandra\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\cl.exe' failed with exit sta
tus 2

    ----------------------------------------
Command "c:\python27\python.exe -u -c "import setuptools, tokenize;__file__='c:\\users\\chandra\\appdata\\local\\temp\\pip-build-3qbbxo\\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\chandra\appdata\local\temp\pip-rskyc7-record\install-record.txt --single-version-externally-managed --compile" failed with error code
1 in c:\users\chandra\appdata\local\temp\pip-build-3qbbxo\MySQL-python\

您的系统上需要一个C编译器。最简单的方法是使用Microsoft提供的


关于Python:

pip install mysql-python
首先检查python是否在命令提示符下正常运行

如果没有,请下载并安装python 2.7

下载后,通常必须进入控制面板>系统>高级系统设置>高级选项卡>环境变量>路径>编辑。这里您需要添加Python安装的Windows路径。例如,我的是“C:\Python27”。如果不将其添加到Path变量中,您将无法从命令行运行Python,并且测试东西会很烦人

安装pip:

pip install mysql-python
接下来,我们应该安装pip,Python包管理器(本节中的一些内容来自于这个stackoverflow页面中的一些经验)。如果您想知道,Python3.4已经安装了pip!但是如果你没有,有几个选择。如果您的计算机上安装了easy_,只需导航到Python27\Scripts目录并键入:

easy_install.exe pip
这将为您安装pip。如果没有easy_安装,可以从下载python脚本。确保将get-pip.py文件保存为.py文件而不是.txt文件。然后可以运行脚本:

 python get-pip.py
一旦安装了pip,您就可以像以前一样将pip所在的目录添加到您的路径中(可能类似于“C:\Python27\Scripts”)

关于MySQL:

pip install mysql-python
在安装pip或其他软件包时,您可能会遇到找不到
vcvvarsall.bat
的错误(我是在尝试安装mysql python软件包时发现的)。这意味着Windows找不到pip用来安装软件包和自行安装的C/C++编译器(它正在寻找Visual Studio)

最后测试它:

pip install mysql-python
通过转到命令提示符并键入以下内容,可以检查mysql python是否正确安装:

C:\> python
>>>import MySQLdb

最简单的方法是使用预编译的python软件包,可以在这里找到,经过大量研究,甚至下载了用于python扩展的非官方windows二进制文件,再次令人失望。 最后,在尝试简单地遵循命令之后,它成功了

easy_install mysql-python

最好的方法是安装
mysqlclient
,以防在安装
mysql-python
时出错
mysqlclient
是它的一个分支,因此它可以用作替代品,它还包含
MySQLdb
。所以,最好还是去它的/P>我的系统已经有Visual C++编译器了,虽然我用新的C++编译器修复了它。仍然收到相同的错误Python已正确安装在我的系统中,路径也已正确设置。@Rahulchandra问题都与mysql连接器有关。看,这是答案。这可能会帮助您确定。您缺少config win.h文件。请使用其中包含的版本(32/64位OS,Mysql)编辑您的问题。问题是关于mysql connector@ShivkumarKondi的:请不要仅仅为了在技术名称中添加粗体而进行编辑——它们不需要这些名称,因为这不会使它们更具可读性。一个更有用的编辑是修正案例错误——它们在这里都错了。如果观察到Python、Django、Windows和MySQL的正确大小写,它们的可读性会更好。谢谢