Virtualenv pip mysqldb mac os X python

I tried this http://jazstudios.blogspot.com/2010/07/installing-mysql-python-mysqldb-in.html tip for installing mysql-python (mysqldb) inside virtualenv (named dogme). (This post points out two important things:

export ARCHFLAGS="-arch x86_64"
echo "mysql_config = /opt/local/bin/mysql_config5" >> ./dogme/build/MySQL-python/site.cfg

to help compile mysqldb)

but, when after, I run python, import MySQLdb, I get the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/.virtualenvs/dogme/lib/python2.5/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/home/.virtualenvs/dogme/lib/python2.5/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /home/.virtualenvs/dogme/lib/python2.5/site-packages/_mysql.so
  Expected in: flat namespace
 in /home/.virtualenvs/dogme/lib/python2.5/site-packages/_mysql.so

Does anyone understand what is wrong?

+3
source share
1 answer

I had a similar problem, see my trace:

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: dlopen(/Library/Python/2.6/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.16.dylib
  Referenced from: /Library/Python/2.6/site-packages/_mysql.so
  Reason: image not found

What I did was put these variables in mine .bash_profile:

export DYLD_LIBRARY_PATH="/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH"

And when I launched the CGI Python application with Apache, I set the same variable with the SetEnv directive:

<Directory "/path/to/app">
    SetEnv DYLD_LIBRARY_PATH /usr/local/mysql/lib/:$DYLD_LIBRARY_PATH
    ...
</Directory>

And now everything works.

+2
source

Source: https://habr.com/ru/post/1791158/


All Articles