virtualenv(python3.4), pip install mysqlclient 错误

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

virtualenv(python3.4), pip install mysqlclient error

pythonmysqldjangovirtualenv

提问by hongjooy

I created virtualenv for django 1.9 project. I am trying to pip install mysqlclient or mysql-python but both of them gives me errors.

我为 django 1.9 项目创建了 virtualenv。我正在尝试 pip install mysqlclient 或 mysql-python 但它们都给了我错误。

pip install mysqlclient

pip install mysql-python

both give me the same error message:

两者都给我相同的错误消息:

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/r4/bkv_4t9s4r140pjkgv6lsq8w0000gn/T/pip-build-cdxcssp9/mysqlclient

命令“python setup.py egg_info”失败,错误代码 1 在 /private/var/folders/r4/bkv_4t9s4r140pjkgv6lsq8w0000gn/T/pip-build-cdxcssp9/mysqlclient

any suggestions!?

有什么建议!?

采纳答案by arcegk

Try to run this before:

尝试在此之前运行:

Ubuntu:

Ubuntu:

sudo apt-get install python-dev python3-dev
sudo apt-get install libmysqlclient-dev
pip install pymysql
pip install mysqlclient

In OSX:

在 OSX 中:

sudo xcodebuild -license accept
brew install mysql-connector-c

回答by hkjamil

  1. Download the MySQL APT repository config tool (you can see more details here: http://dev.mysql.com/downloads/repo/apt/)

    wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
    
  2. Install the MySQL APT repository config tool

    dpkg -i mysql-apt-config_0.7.3-1_all.deb
    
  1. 下载 MySQL APT 存储库配置工具(您可以在此处查看更多详细信息:http: //dev.mysql.com/downloads/repo/apt/

    wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
    
  2. 安装 MySQL APT 存储库配置工具

    dpkg -i mysql-apt-config_0.7.3-1_all.deb
    

You will be asked to select product and version that you want to install. In the first step, select Server and next select either mysql-5.6 or mysql-5.7. Then click Apply.

系统将要求您选择要安装的产品和版本。在第一步中,选择服务器,然后选择 mysql-5.6 或 mysql-5.7。然后单击应用。

  1. Update APT

    apt-get update
    
  2. Install the server

    sudo apt-get install mysql-community-server
    
    sudo apt-get install python-dev python3-dev
    sudo apt-get install libmysqlclient-dev
    pip install pymysql
    pip install mysqlclient
    
  1. 更新 APT

    apt-get update
    
  2. 安装服务器

    sudo apt-get install mysql-community-server
    
    sudo apt-get install python-dev python3-dev
    sudo apt-get install libmysqlclient-dev
    pip install pymysql
    pip install mysqlclient
    

回答by karjaubayev

If you are using Python 2.x, and already have installed:

如果您使用的是 Python 2.x,并且已经安装:

  • MySQL Server
  • Python Connector
  • MySQL服务器
  • Python 连接器

Then the problem is when you run:

那么问题是当你运行时:

Windows:

视窗:

(your environment) SomePath> pip install mysqlclient 

Mac OS:

苹果系统:

$ pip install mysqlclient

Actually it is asking to install package for Python 3.x not 2.x. So it is throwing an error.

实际上,它要求为 Python 3.x 而不是 2.x 安装包。所以它抛出一个错误。

Solutionis to run:

解决方法是运行:

Windows:

视窗:

(your environment) SomePath> pip install mysqlclient==1.3.9

Mac OS:

苹果系统:

$ pip install mysqlclient==1.3.9

P.S The mysqlclient==1.3.9version is the latest version for Python 2.x

PS mysqlclient==1.3.9版本是 Python 2.x 的最新版本

回答by Akash Desarda

If you're using Anaconda (which I highly suggest you) then run these two commands

如果您使用的是 Anaconda(我强烈建议您),请运行这两个命令

conda install -c anaconda mysql-connector-python

and

conda install -c bioconda mysqlclient

回答by louis_guitton

This is probably due to your mysql_configbeing broken.

这可能是因为你mysql_config被打破了。

As of 2019, here is how to run smoothly pip install mysqlclienton MacOS:

截至 2019 年,以下是如何pip install mysqlclient在 MacOS 上顺利运行:

brew info openssland follow the commands at the bottom

brew info openssl并按照底部的命令

  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

Other approaches:

其他方法:

  • brew install/upgrade/reinstall mysql: did not fix the issue for me, but has the nice side effect to make sure your installation is clean.
  • brew install mysql-connector-c: to make that work you have to unlink mysql, which ruins your setup and it did not fix the issue for me.
  • brew install/upgrade/reinstall mysql: 没有为我解决这个问题,但有一个很好的副作用来确保你的安装是干净的。
  • brew install mysql-connector-c:要完成这项工作,您必须取消与 mysql 的链接,这会破坏您的设置并且没有为我解决问题。