Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

virtualenv(python3.4), pip install mysqlclient error

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.

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

any suggestions!?

like image 268
hongjooy Avatar asked Feb 04 '16 00:02

hongjooy


People also ask

How do I fix Pip error mysqliclient installation error?

If a problem arises, pip will throw an error with a message like mysqliclient installation error. First, check that you are connected to the internet and it is stable. Try to run the command again. Next, you will have to manually download and install the package if the problem persists.

How to install mysqlclient in Python 3?

You can easily install the mysqlclient in python3.* virtual environment or at system level just follow these steps: Don't forget to update the python version as per your need, and for python2.7 use If you're installing the same at the system level then add sudo in the beginning of the command.

What is MySQL client in Python?

This is a database client application that serves as the medium/interface between the user running Python codes and the mysql database. mysqlclient was developed to replace MySql-python and provides support for Python3, although it is backward compatible as well.

Why can’t I run MySQL in a virtual environment?

This generally happens if you have multiple versions of python installed in your system. First, uninstall mysqlclient and pymysql globally (if installed): If using pycharm, it will popup for setting up an interpreter. Select python3.6 as your interpreter and create a virtual environment. If not using pycharm, This should work!


2 Answers

Try to run this before:

Ubuntu:

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

In OSX:

sudo xcodebuild -license accept
brew install mysql-connector-c
like image 151
arcegk Avatar answered Oct 18 '22 22:10

arcegk


This is probably due to your mysql_config being broken.

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

brew info openssl and follow the commands at the bottom

  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.
like image 5
louis_guitton Avatar answered Oct 18 '22 22:10

louis_guitton