Python pip安装mysqlclient错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51062920/
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:42:25  来源:igfitidea点击:

pip install mysqlclient error

pythonmysqlpipbuild-tools

提问by Gargantua

i'm tryng to import mysqlclientlibrary for python with pip, when i use the command
pip install mysqlclientit return an error:

我正在尝试使用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\

I've already installed Microsoft Build Tools 2015but the problem persist

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

回答by Bishu rudra paul

First install python 3.6.5, then run

先安装python 3.6.5,然后运行

pip install mysqlclient==1.3.12

回答by Sayse

For me, it was a mixture of an old setup tools and missing packages

对我来说,它混合了旧的设置工具和缺少的包

pip install --upgrade setuptools

apt install gcc libssl-dev

回答by Lai Niel

Try download and install from wheel instead. Take note of your python version and download the correct one.

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

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

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

回答by Ankit Chaurasia

  1. Install build-essential

    sudo apt-get install build-essential

  2. Install mysqlclient

    pip install mysqlclient

  1. 安装 build-essential

    sudo apt-get install build-essential

  2. 安装 mysqlclient

    pip install mysqlclient

回答by Vince D

Try pip install --only-binary :all: mysqlclientWorked for me

试试 pipinstall --only-binary :all: mysqlclient对我有用

回答by Ashish Nandan

First try this command

先试试这个命令

(keep space properly ie, pip space install space --only-binary space :all: space mysqlclient)

(适当保留空间,即 pip space install space --only-binary space :all: space mysqlclient)

pip install --only-binary :all: mysqlclientif still error then try this... Go to this website Python Extension packageand press ctrl+F and search mysqlclient. You will find a file name like this.. mysqlclient?1.4.5?cp38?cp38?win_amd64.whl

pip install --only-binary :all: mysqlclient如果仍然错误,那么试试这个...去这个网站Python 扩展包并按 ctrl+F 并搜索 mysqlclient。你会找到这样的文件名.. mysqlclient?1.4.5?cp38?cp38?win_amd64.whl

Choose carefully ---According to python version There is a step given to choose it.

慎重选择---根据python版本给出了选择的步骤。

  1. cp38 means for python 3.8 version and cp 37 means for python 3.6 version so first check your python version wether it is 3.8,3.7,3.6,3.5,3.4 then download accordingly.

  2. amd64--- while checking python version also check whether your python is of 64-bit or 32-bit. then select accordingly. If your python is of 32-bit then select amd32.

  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。

Otherwise you will face problem. Then download the file and install it manually using pip command. There are steps given below:-

否则你会遇到问题。然后下载文件并使用 pip 命令手动安装它。有以下步骤:-

After download open command prompt and go to that directory where that downloaded file available( or better to cut that file and paste into your desktop) and type: 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

下载后打开命令提示符并转到该下载文件可用的目录(或更好地剪切该文件并粘贴到您的桌面)并键入: 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

回答by Ashish Nandan

Better if you install python 64-bit. Then pip install mysqlclientwill work sure otherwise you can follow these stepssteps to install using python extension packages

如果你安装 python 64 位更好。然后pip install mysqlclient肯定会工作,否则您可以按照这些步骤步骤使用python扩展包进行安装