簡體   English   中英

為 flask 安裝 mysql-python 時出錯

[英]Getting errors while installing mysql-python for flask

我正在使用 python v3.7。 我想為 flask 應用程序安裝 mysql-python。 我得到ModuleNotFoundError: No module named 'MySQLdb' ,並在互聯網上搜索我發現這可以通過安裝mysql-pythonmysqlclient來解決。 但是,當我嘗試使用命令pip install mysql-python出現以下錯誤時。 請幫助解決它們。 謝謝你。

    Defaulting to user installation because normal site-packages is not writeable
Collecting mysql-python
  Using cached MySQL-python-1.2.5.zip (108 kB)
Building wheels for collected packages: mysql-python
  Building wheel for mysql-python (setup.py): started
  Building wheel for mysql-python (setup.py): finished with status 'error'
  ERROR: Command errored out with exit status 1:
   command: 'c:\program files (x86)\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Anshu\\AppData\\Local\\Temp\\pip-install-hx2vj4vu\\mysql-python\\setup.py'"'"'; __file__='"'"'C:\\Users\\Anshu\\AppData\\Local\\Temp\\pip-install-hx2vj4vu\\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\Anshu\AppData\Local\Temp\pip-wheel-rqv0mwcp'
       cwd: C:\Users\Anshu\AppData\Local\Temp\pip-install-hx2vj4vu\mysql-python\
  Complete output (29 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win32-3.7
  copying _mysql_exceptions.py -> build\lib.win32-3.7
  creating build\lib.win32-3.7\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
  copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
  creating build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.7\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
  running build_ext
  building '_mysql' extension
  creating build\temp.win32-3.7
  creating build\temp.win32-3.7\Release
  C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -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:\program files (x86)\python37-32\include" "-Ic:\program files (x86)\python37-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" /Tc_mysql.c /Fobuild\temp.win32-3.7\Release\_mysql.obj /Zl
  _mysql.c
  c:\program files (x86)\python37-32\include\pyconfig.h(203): fatal error C1083: Cannot open include file: 'basetsd.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
  ----------------------------------------
  ERROR: 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: started
    Running setup.py install for mysql-python: finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: 'c:\program files (x86)\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Anshu\\AppData\\Local\\Temp\\pip-install-hx2vj4vu\\mysql-python\\setup.py'"'"'; __file__='"'"'C:\\Users\\Anshu\\AppData\\Local\\Temp\\pip-install-hx2vj4vu\\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\Anshu\AppData\Local\Temp\pip-record-q9lznfeo\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\Anshu\AppData\Roaming\Python\Python37\Include\mysql-python'
         cwd: C:\Users\Anshu\AppData\Local\Temp\pip-install-hx2vj4vu\mysql-python\
    Complete output (29 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    copying _mysql_exceptions.py -> build\lib.win32-3.7
    creating build\lib.win32-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
    creating build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\REFRESH.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
    running build_ext
    building '_mysql' extension
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7\Release
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -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:\program files (x86)\python37-32\include" "-Ic:\program files (x86)\python37-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" /Tc_mysql.c /Fobuild\temp.win32-3.7\Release\_mysql.obj /Zl
    _mysql.c
    c:\program files (x86)\python37-32\include\pyconfig.h(203): fatal error C1083: Cannot open include file: 'basetsd.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
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\program files (x86)\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Anshu\\AppData\\Local\\Temp\\pip-install-hx2vj4vu\\mysql-python\\setup.py'"'"'; __file__='"'"'C:\\Users\\Anshu\\AppData\\Local\\Temp\\pip-install-hx2vj4vu\\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\Anshu\AppData\Local\Temp\pip-record-q9lznfeo\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\Anshu\AppData\Roaming\Python\Python37\Include\mysql-python' Check the logs for full command output.

Sometimes people face same error with visual C++ tools, launch setup again and also select windows 8.1 / 10 SDK depending upon your OS. 這將修復 basestd.h 錯誤。

如果仍然無法正常工作,請嘗試從以下位置啟動構建工具:C:\Program Files (x86)\Microsoft Visual C++ Build Tools。

另一種選擇是,只需安裝 anaconda 2 或 3(64 位,如果您也不想出現 memory 錯誤)。 It contains all the important packages prebuilt: sklearn, matplotlib, scipy, numpy, pandas and even web development frameworks such as flask.

我希望這會有所幫助<3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM