0

I'm new to using virtualenv and I'm having trouble installing MySQLdb on my virtualenv.

I'm currently using Python 2.7 and here is what my current virtualenv looks like

click==6.7
Flask==1.0.2
Flask-SQLAlchemy==2.3.2
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
MySQL-python==1.2.5
mysqlclient==1.3.12
SQLAlchemy==1.2.8
Werkzeug==0.14.1

I first saw this error when I was coding on my normal machine (Mac 10.13), and when I initially tried to install MySQLdb, I got this error.

Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-rxnRuR/MySQL-python/

I was able to fix it by using the second solution in this question

However, when I start up my virtual environment and attempt to install MySQLdb I get the same error code as above, but I do not have the same directories that are provided in the solution I originally found.

I've tried to piece together solutions from the follow questions trying to see if there is a solution for installing MySQLdb in virtualenv Link1, Link2, Link3, but none of them seem to work

I was hoping someone might be able to explain what's going on so that I work with MySQLdb in a virtual environment.

Commands tried:

sudo pip install --upgrade setuptools
brew install mysql
brew install mysql-python

brew uninstall mysql
brew install mysql-connector-c
brew unlink mysql-connector-c
brew install mysql
pip install mysql-python

UPDATE: This seems to be a known issue and is in a Github thread I ended up solving the above error code using the solution found here, but now when I start up Python and I try to import MySQLdb, I get the following error code

Reason: image not found 
R. Zh
  • 51
  • 6

2 Answers2

0

Try this :

  1. brew uninstall mysql-connector-c
  2. brew install mysql
  3. invoke "mysql_config --libs" and confirm its output include correct library options: "-L/usr/local/Cellar/mysql/5.7.20/lib -lmysqlclient -lssl -lcrypto"
  4. export LDFLAGS=-L/usr/local/opt/openssl/lib && pip install mysqlclient

I hope this helps

Mahrez BenHamad
  • 1,791
  • 1
  • 15
  • 21
  • I think I tried it in some form or another before, but I just tried it again right now just in case, Unfortunately it still gives me the same error code :( thanks though – R. Zh Jun 18 '18 at 22:41
  • I changed my answer I hope that helps :) – Mahrez BenHamad Jun 19 '18 at 21:29
  • Yep! I recently made it that far. I posted an update and one of the solutions given was the one you wrote down. Now I'm trying to **import MySQLdb** within python and I get the error posted in my update. If you have any info please let me know! – R. Zh Jun 19 '18 at 21:45
  • try to reinstall it, This might help – Mahrez BenHamad Jun 19 '18 at 21:57
0

The answer in this other question solved the problem, below is the command I used to make it work.

export DYLD_FALLBACK_LIBRARY_PATH=/anaconda2/lib/:$DYLD_FALLBACK_LIBRARY_PATH

A few notes however...

  • I had to run this command WITHIN my virtual environment for it to work, not my global environment
  • I was told this is a problem with Anaconda managing my packages and my virtual environment variables not being able to find the correct paths
  • You'll notice that my folder is "~/anaconda2/..." check to see where your lib files are installed on your global environment and make sure you adjust the directory name accordingly
  • Also I was suggested to keep this command in an initialization file for my virtual environment, that way whenever my virtual environment loads, this command is already executed
R. Zh
  • 51
  • 6