在 Windows 中的 Python 3.6 中安装 mysqlclient

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51146117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:45:55  来源:igfitidea点击:

Installing mysqlclient in Python 3.6 in windows

pythonpipmysql-pythonpython-wheel

提问by Damian

I want to install MySqlclient on my windows system. I am Currently using Python 3.6. After going through the various post over Stackoverflow, I could Not find the correct way. This is what I have done so far:

我想在我的 Windows 系统上安装 MySqlclient。我目前使用 Python 3.6。在通过 Stackoverflow 浏览了各种帖子后,我找不到正确的方法。这是我到目前为止所做的:

1) Installation by using pip pip install mysqlclient. Error:

1) 使用 pip 安装pip install mysqlclient。错误:

Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools" http://landinghub.visualstudio.com/visual-cpp-build-tools

需要 Microsoft Visual C++ 14.0。使用“Microsoft Visual C++ 构建工具”获取它http://landinghub.visualstudio.com/visual-cpp-build-tools

I already have Microsoft Visual C++ installed on my laptop. Some are saying you need 2015 edition.

我的笔记本电脑上已经安装了 Microsoft Visual C++。有人说你需要2015版。

2) Installation by using wheel file pip install mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl. Error:

2)使用wheel文件安装pip install mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl。错误:

Requirement mysqlclient-1.3.13-cp36-cp36m-win_amd64.whllooks like a filename, but the file does not exist. mysqlclient-1.3.13-cp36-cp36m-win_amd64.whlis not a supported wheel on this platform.

需求mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl看起来像一个文件名,但该文件不存在。 mysqlclient-1.3.13-cp36-cp36m-win_amd64.whl不是此平台上受支持的轮子。

2.1) Changing the whl file to different version pip install mysqlclient-1.3.13-cp36-cp36m-win32.whl. Error:

2.1) 将 whl 文件更改为不同的版本pip install mysqlclient-1.3.13-cp36-cp36m-win32.whl。错误:

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'C:\\Users\\Foxtrot\\Desktop\\finaltest\\mysqlclient-1.3.13-cp36-cp36m-win32.whl'

由于环境错误,无法安装软件包:[Errno 2] 没有这样的文件或目录: 'C:\\Users\\Foxtrot\\Desktop\\finaltest\\mysqlclient-1.3.13-cp36-cp36m-win32.whl'

Other things that are done: updated setuptools, updated wheel.

完成的其他事情:更新的设置工具,更新的轮子。

采纳答案by 3sky

I can't find mysqlclient-1.3.13's whl file on PyPi. So you need to compile it from source. Unfortunately it's not easy. I'm not Windows guy, so I only can recommend guide like this

我在PyPi上找不到 mysqlclient-1.3.13 的 whl 文件。所以你需要从源代码编译它。不幸的是,这并不容易。我无法在Windows的家伙,所以我只能推荐指南像这样

回答by CodeSamurai777

Had the same problem, searched the web etc. Here this answer:

有同样的问题,在网上搜索等。这里是这个答案:

mysql-python install error: Cannot open include file 'config-win.h'

mysql-python 安装错误:无法打开包含文件“config-win.h”

It has all the instructions. In short go to this site: https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient:

它有所有的说明。总之去这个网站:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

There you will find mysqlclient?1.3.13?cp36?cp36m?win32.whlmysqlclient?1.3.13?cp36?cp36m?win_amd64.whl

在那里你会发现 mysqlclient?1.3.13?cp36?cp36m?win32.whlmysqlclient?1.3.13?cp36?cp36m?win_amd64.whl

Download the correct file for your platform.

下载适合您平台的正确文件。

Then use your downloaded wheels file with pip and your done:

然后将下载的轮子文件与 pip 一起使用并完成:

pip install c:\mysqlclient?1.3.13?cp36?cp36m?win_amd64.whl

pip install c:\mysqlclient?1.3.13?cp36?cp36m?win_amd64.whl

The https://www.lfd.uci.edu/~gohlke/pythonlibshas lots of lots of compiled libaries to solve the problem of building them from source yourself. They even compile them for python 3.7 :)

https://www.lfd.uci.edu/~gohlke/pythonlibs有很多很多编译libaries的解决,从源头自行构建他们的问题。他们甚至为 python 3.7 编译它们:)

Alternative Solution

替代方案

You can also download Visual C++ Build Tools and then you should be able to install every (at least to my knowledge) version of mysqlclient with pip. To do this go to this site: https://www.scivision.co/python-windows-visual-c++-14-required/there you can find out which version of Build Tools you need and you can also find a link to download the installer. Be aware though Build Tools require more than 4GB of free disk space.

您还可以下载 Visual C++ 构建工具,然后您应该能够使用 pip 安装每个(至少据我所知)mysqlclient 版本。为此,请访问此站点:https: //www.scivision.co/python-windows-visual-c++-14-required/在那里您可以找到所需的构建工具版本,还可以找到指向下载安装程序。请注意,构建工具需要超过 4GB 的可用磁盘空间。

回答by Dinesh Sharma

I am using python3.7 on Windows 10 operating system. I had same issue and after a long research I had installed it successfully.

我在 Windows 10 操作系统上使用 python3.7。我遇到了同样的问题,经过长时间的研究,我成功安装了它。

Install "Microsoft Visual C++ Build Tools" AND My OS is having 64 bit operating system but still then it need to install 32 bit version "mysqlclient?1.4.2?cp37?cp37m?win32.whl"

安装“Microsoft Visual C++ Build Tools”并且我的操作系统是 64 位操作系统,但仍然需要安装 32 位版本“mysqlclient?1.4.2?cp37?cp37m?win32.whl”

Download binary wheels from "https://www.lfd.uci.edu/~gohlke/pythonlibs/" and run command

从“ https://www.lfd.uci.edu/~gohlke/pythonlibs/”下载二进制轮子并运行命令

pip install [path_to_downloaded_file] eg: C:\Users\Ds\mysqlclient-1.4.2-cp37-cp37m-win32.whl

pip install [path_to_downloaded_file] 例如:C:\Users\Ds\mysqlclient-1.4.2-cp37-cp37m-win32.whl

use pipenv instead of pip if you are using virtual environment.

如果您使用的是虚拟环境,请使用 pipenv 而不是 pip。

回答by Ildar Akhmetov

The error means that the package has not yet been compiled for your versions of OS and Python. So pip tries to build it from the source for you.

该错误意味着该包尚未针对您的 OS 和 Python 版本进行编译。因此 pip 会尝试从源头为您构建它。

There are two possible solutions.

有两种可能的解决方案。

  1. The first option is to install the most recent version of Microsoft Visual C++ Build Tools. Just go ahead and download it from the Microsoft website. Then pip should be able to compile the package.

  2. Another option is using an unofficial binary. As mentioned here, a resource proved to be useful is https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python. Just download the pre-compiled package and install it using

    pip install c:\path-to-a-pre-compiled-package

  1. 第一个选项是安装最新版本的 Microsoft Visual C++ Build Tools。继续并从 Microsoft 网站下载它。然后 pip 应该能够编译包。

  2. 另一种选择是使用非官方的二进制文件。正如这里提到的,一个被证明有用的资源是https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python。只需下载预编译包并使用

    pip install c:\path-to-a-pre-compiled-package

回答by Taurai Benhura

Tell pipnot to use sources and use binary packages instead:

告诉pip不要使用源代码,而是使用二进制包:

pip install --only-binary :all: mysqlclient

https://pip.pypa.io/en/stable/reference/pip_install/#install-only-binary

https://pip.pypa.io/en/stable/reference/pip_install/#install-only-binary

回答by heySushil

for this error, most of user's suggest to install vs build but there is an alternative which works perfectly in my case and is sure for you too. Download latest MySQL client from here mysqlclients

对于此错误,大多数用户建议安装 vs build,但有一种替代方法在我的情况下非常有效,并且对您也适用。从这里下载最新的 MySQL 客户端 mysqlclients

Here you can see many version but prefer to download the latest one which has 32 bit and 64-bit files. download theme and past the file on your projects root folder then run the same command but with the full file name of downloaded mysqlclient.

在这里您可以看到许多版本,但更喜欢下载包含 32 位和 64 位文件的最新版本。下载主题并通过项目根文件夹中的文件,然后运行相同的命令,但使用下载的 mysqlclient 的完整文件名。

like: pip install mysqlclient?1.4.6?cp38?cp38?win32.whl

in my case, the file is this also if have already the XAMPP server then you can use its PHPMyAdmin with python. You just need to change on your roots setting.py file for this. Something like this

在我的情况下,如果已经有 XAMPP 服务器,该文件也是这个,那么您可以将其 PHPMyAdmin 与 python 一起使用。为此,您只需要更改您的根 setting.py 文件即可。像这样的东西

 DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydjango',
        'USER': 'root',
        'PASSWORD':'',
        'HOST':'localhost',
        'PORT':'3306',
    }
}

The port is the same which you see on xampp panel just before the start button of MySQL. After changing this you just again start your server by hitting this command

该端口与您在 xampp 面板上看到的 MySQL 开始按钮之前的端口相同。更改此设置后,您只需点击此命令即可再次启动服务器

python manage.py runserver

If you didn't see any error then congratulations you successfully connected with MySQL database.

如果您没有看到任何错误,那么恭喜您成功连接到 MySQL 数据库。

Enjoy...

享受...

回答by Sahaj Rohilla

The easiest way to solve this problem is to download the correct version of MySQL client that supports the python version installed on your system.

解决此问题的最简单方法是下载正确版本的 MySQL 客户端,该版本支持您系统上安装的 python 版本。

MYSQLclient download link: https://pypi.org/project/mysqlclient/#files

MYSQLclient下载链接:https://pypi.org/project/mysqlclient/#files

enter image description here

在此处输入图片说明

Check the python version installed in your PC: enter image description here

检查您的 PC 中安装的 python 版本: 在此处输入图片说明

回答by MoBoo

Had the same problem just day. Tried to install mysqlclient on a Windows Server R2.

刚刚有同样的问题。尝试在 Windows Server R2 上安装 mysqlclient。

[...]

[...]

Tl;dr

Tl;博士

  1. "MySQL Connector C 6.1" was installed in the wrong directory:"C:\Program Files\MySQL" instead of "C:\Program Files (x86)\MySQL" where it should be for me.
    --> Copied "MySQL Connector C 6.1" to "C:\Program Files (x86)\MySQL" Directory.

  2. "C:\Users\MoBoo\AppData\Local\Temp" was Read-Only:Therefore pip couldn't compile files into Temp dir.
    --> Allow Write access to "C:\Users\MoBoo\AppData\Local\Temp" Directory.

  1. “MySQL Connector C 6.1”安装在错误的目录中:“C:\Program Files\MySQL”而不是“C:\Program Files (x86)\MySQL”对我来说应该是这样。
    --> 将“MySQL Connector C 6.1”复制到“C:\Program Files (x86)\MySQL”目录。

  2. “C:\Users\MoBoo\AppData\Local\Temp”是只读的:因此 pip 无法将文件编译到 Temp 目录中。
    --> 允许写入访问“C:\Users\MoBoo\AppData\Local\Temp”目录。

回答by tormuto

Here is what worked for me. I uninstalled mysql and re-installed it.

这对我有用。我卸载了mysql并重新安装了它。

pip uninstall mysqlclient

Then simply re-install, so it picked the current version "1.4.2.post1"

然后简单地重新安装,所以它选择了当前版本“1.4.2.post1”

pip install mysqlclient

Which interestingly, works straightaway.

有趣的是,它可以直接工作。