pip安装mysqlclient错误

时间:2018-06-27 12:33:49

标签: python mysql pip build-tools

当我使用命令
时,我正尝试使用 pip 为python导入 mysqlclient 库。 pip install mysqlclient返回错误:

Collecting mysqlclient
Using cached     https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command c:\users\astrina\appdata\local\programs\python\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\astrina\\AppData\\Local\\Temp\\pip-install-40l_x_f4\\mysqlclient\\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\astrina\AppData\Local\Temp\pip-record-va173t5v\install-record.txt --single-version-externally-managed --compile:
c:\users\astrina\appdata\local\programs\python\python36\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
  warnings.warn(msg)
running install
running build
running build_py
creating build
creating build\lib.win-amd64-3.6
copying _mysql_exceptions.py -> build\lib.win-amd64-3.6
creating build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\compat.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\connections.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\converters.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\cursors.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\release.py -> build\lib.win-amd64-3.6\MySQLdb
copying MySQLdb\times.py -> build\lib.win-amd64-3.6\MySQLdb
creating build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.6\MySQLdb\constants
copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.6\MySQLdb\constants
running build_ext
building '_mysql' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

----------------------------------------
Command "c:\users\astrina\appdata\local\programs\python\python36\python.exe -u -c "import setuptools, 
tokenize;__file__='C:\\Users\\astrina\\AppData\\Local\\Temp\\pip-install- 
40l_x_f4\\mysqlclient\\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\astrina\AppData\Local\Temp\pip- 
record-va173t5v\install-record.txt --single-version-externally-managed -- 
compile" failed with error code 1 in C:\Users\astrina\AppData\Local\Temp\pip- 
install-40l_x_f4\mysqlclient\

我已经安装了 Microsoft Build Tools 2015 ,但问题仍然存在

11 个答案:

答案 0 :(得分:9)

首先安装python 3.6.5,然后运行

pip install mysqlclient==1.3.12

答案 1 :(得分:2)

对我来说,这是旧的设置工具和缺少的软件包的组合

pip install --upgrade setuptools

apt install gcc libssl-dev

答案 2 :(得分:1)

安装以下软件包即可解决问题。

[1, 2, 3, 2]
[3]
[1, 2, 3]
[1, 2, 3]
[1, 2, 3, 2, 3, 1, 2, 3, 1, 2, 3]

答案 3 :(得分:0)

请尝试从转轮下载并安装。记下您的python版本并下载正确的版本。

https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient

答案 4 :(得分:0)

尝试点install --only-binary :all: mysqlclient 为我工作

答案 5 :(得分:0)

首先尝试此命令

  

(正确保留空间,即点子空间安装空间--only-binary   空格:all:空格mysqlclient)

pip install --only-binary :all: mysqlclient 如果仍然有错误,请尝试... 转到此网站Python Extension package,然后按ctrl + F并搜索mysqlclient。您会找到这样的文件名。 mysqlclient‑1.4.5‑cp38‑cp38‑win_amd64.whl

仔细选择---根据python版本 有一个选择步骤。

  1. cp38表示python 3.8版本,而cp 37表示python 3.6版本,因此首先检查python版本是否为3.8、3.7、3.6、3.5、3.4,然后进行相应下载。

  2. amd64 ---在检查python版本时,还要检查您的python是64位还是32位。然后相应地选择。如果您的python是32位的,则选择amd32。

否则,您将面临问题。 然后下载文件并使用pip命令手动安装。 有以下步骤:-

下载后,打开命令提示符并转到该下载文件可用的目录(或者最好将其剪切并粘贴到您的桌面上),然后键入: NOTE :- PLEASE TYPE AFTER DOWNLOAD THE FILE... This is for python 3.8 and 64-bit $ pip install mysqlclient‑1.4.5‑cp38‑cp38‑win_amd64.whl For python 3.7 and 32-bit $ pip install mysqlclient‑1.4.5‑cp37‑cp37m‑win32.whl

答案 6 :(得分:0)

最好安装64位python。然后pip install mysqlclient将可以正常工作,否则您可以按照以下步骤操作steps to install using python extension packages

答案 7 :(得分:0)

  1. 安装build-essential

    sudo apt-get install build-essential

  2. 安装mysqlclient

    pip install mysqlclient

答案 8 :(得分:0)

You can set ssl library path explicitly.

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient

答案 9 :(得分:0)

您可能需要安装Python 3和MySQL开发标头和库,如下所示: 对于UBUNTU或Debian

sudo apt-get install python3-dev default-libmysqlclient-dev build-essential

Red Hat / CentOS

sudo yum install python3-devel mysql-devel

然后尝试

pip install mysqlclient

答案 10 :(得分:-1)

我遇到了同样的问题,并且以非常愚蠢的方式解决了。我刚刚卸载了python,并通过Microsoft Store安装了它。