Have MySQLdb installed, works outside of virtualenv but inside it doesn't exist. How to resolve?

◇◆丶佛笑我妖孽 提交于 2019-12-03 12:28:38

If you have created the virtualenv with the --no-site-packages switch (the default), then system-wide installed additions such as MySQLdb are not included in the virtual environment packages.

You need to install MySQLdb with the pip command installed with the virtualenv. Either activate the virtualenv with the bin/activate script, or use bin/pip from within the virtualenv to install the MySQLdb library locally as well.

Alternatively, create a new virtualenv with system site-packages included by using the --system-site-package switch.

fwindpeak
  1. source $ENV_PATH/bin/activate
  2. pip uninstall MySQL-python
  3. pip install MySQL-python

this worked for me.

I went through same problem, but using pip from virtualenv didn't solve the problem as I got this error

error: could not delete '/Library/Python/2.7/site-packages/_mysql.so': Permission denied

Earlier I had installed the package by sudo pip install mysql-python

To solve, copy files /Library/Python/2.7/site-packages/MySQL_python-1.2.5-py2.7.egg-info and /Library/Python/2.7/site-packages/_mysql* to ~/v/lib/python-2.7/site-packages and include /usr/local/mysql/lib in DYLD_LIBRARY_PATH env variable.

For the second step I am doing export DYLD_LIBRARY_PATH=/usr/local/mysql/lib in ~/.profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!