简体   繁体   English

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

[英]virtualenv(python3.4), pip install mysqlclient error

I created virtualenv for django 1.9 project.我为 django 1.9 项目创建了 virtualenv。 I am trying to pip install mysqlclient or mysql-python but both of them gives me errors.我正在尝试 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!?有什么建议!?

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

This is probably due to your mysql_config being broken.这可能是由于您的mysql_config被破坏了。

As of 2019, here is how to run smoothly pip install mysqlclient on MacOS:截至 2019 年,这里是如何在 MacOS 上顺利运行pip install mysqlclient

brew info openssl and 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/upgrade/reinstall mysql : 没有为我解决这个问题,但有一个很好的副作用来确保你的安装是干净的。
  • 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 mysql-connector-c :要完成这项工作,您必须取消与 mysql 的链接,这会破坏您的设置并且没有为我解决问题。

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
  1. Download the MySQL APT repository config tool (you can see more details here: http://dev.mysql.com/downloads/repo/apt/ )下载 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. Install the MySQL APT repository config tool安装 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.在第一步中,选择服务器,然后选择 mysql-5.6 或 mysql-5.7。 Then click Apply.然后单击应用。

  1. Update APT更新 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

If you are using Python 2.x, and already have installed:如果您使用的是 Python 2.x,并且已经安装:

  • MySQL Server MySQL服务器
  • Python Connector 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.实际上,它要求为 Python 3.x 而不是 2.x 安装包。 So it is throwing an error.所以它抛出一个错误。

Solution is to run:解决方法是运行:

Windows:视窗:

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

Mac OS:苹果系统:

$ pip install mysqlclient==1.3.9

PS The mysqlclient==1.3.9 version is the latest version for Python 2.x PS mysqlclient==1.3.9版本是 Python 2.x 的最新版本

For Ubuntu 18.04对于 Ubuntu 18.04

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

and setup和设置

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', 
        'NAME': 'DB_NAME',
        'USER': 'DB_USER',
        'PASSWORD': 'DB_PASSWORD',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
    }
}

This worked for on Ubuntu 18.04这适用于 Ubuntu 18.04

sudo apt-get install python3.6-dev 
sudo apt-get install mysql-client 
sudo apt-get install libsqlclient-dev 
sudo apt-get install libssl-dev

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM