无法找到安装mysqlclient的正确方法

时间:2019-01-02 18:31:36

标签: python mysql django python-3.x

我已经尝试为我的python 3.7.2安装mysqlclient了一段时间了。 当前使用Windows 10,Python 3.7.2和Wamp Server 2.1

我尝试使用以下内容

1)pip安装mysqlclient

2)pip安装c:\ mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl 以及沿着这些路线的一切 检查了以下链接:Installing mysqlclient in Python 3.6 in windows

3)pip安装“ mysqlclient == 1.3.12”

4)pip install --only-binary:all:mysqlclient

5)pip安装mysql-connector-python

我尝试使用cmd(以管理员身份)执行上述所有操作,但同样失败。

欢迎提供任何解决此问题的方法的人!预先谢谢你!

PS连接器已安装,但我仍然无法迁移。 它给了我以下错误

Traceback (most recent call last):
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\backends\mysql\base.py", line 15, in <module>
    import MySQLdb as Database
ModuleNotFoundError: No module named 'MySQLdb'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\core\management\__init__.py", line 357, in execute
    django.setup()
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\apps\registry.py", line 112, in populate
    app_config.import_models()
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\apps\config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\SOIS\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\SOIS\PycharmProjects\Buggie\Issues\models.py", line 8, in <module>
    from django.contrib.auth.models import User, Group
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\contrib\auth\models.py", line 2, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\contrib\auth\base_user.py", line 47, in <module>
    class AbstractBaseUser(models.Model):
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\models\base.py", line 101, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\models\base.py", line 305, in add_to_class
    value.contribute_to_class(cls, name)
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\models\options.py", line 203, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\utils.py", line 202, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\utils.py", line 110, in load_backend
    return import_module('%s.base' % backend_name)
  File "C:\Users\SOIS\AppData\Local\Programs\Python\Python37-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\Users\SOIS\PycharmProjects\Buggie\venv\lib\site-packages\django\db\backends\mysql\base.py", line 20, in <module>
    ) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

当我尝试安装mysqlclient时:

  ----------------------------------------
  Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command c:\users\sois\appdata\local\programs\python\python37-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\SOIS\\AppData\\Local\\Temp\\pi
p-install-qanlzr18\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --reco
rd C:\Users\SOIS\AppData\Local\Temp\pip-record-uak3sgkf\install-record.txt --single-version-externally-managed --compile:
    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\compat.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\converters.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\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.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
    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\2017\BuildTools\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,3,14,'final',0)
-D__version__=1.3.14 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -Ic:\users\sois\appdata\local\programs\python\python37-32\include -Ic:\users\sois\appdata\local\progra
ms\python\python37-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.16.27023\Include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\
BuildTools\VC\Tools\MSVC\14.16.27023\ATLMFC\Include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0
\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NET
FXSDK\4.6.1\include\um" /Tc_mysql.c /Fobuild\temp.win32-3.7\Release\_mysql.obj /Zl
    _mysql.c
    _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.16.27023\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "c:\users\sois\appdata\local\programs\python\python37-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\SOIS\\AppData\\Local\\Temp\\pip-install-qanlzr18\\mysq
lclient\\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\SOIS\AppData
\Local\Temp\pip-record-uak3sgkf\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\SOIS\AppData\Local\Temp\pip-install-qanlzr18\mysqlc
lient\

PS:我已经安装了最新的Visual Studio构建工具(2017年)

0 个答案:

没有答案