I can create a .pth file and put it in my virtualenv lib\\site-packages
to bring the MySQLdb that is installed by the windows installer into my virtualenv. But so far the only way I have been able to get this to work is if I use this path in the .pth file:
C:\python27\lib\site-packages
This of course now brings in the ENTIRE lib\\site-packages
into the virtualenv.
How do I add ONLY MySQLdb to the virtual environment?
Yes, it's on Windows. No, I can't switch to a real OS for this so I could use add2virtualenv from virtualenvwrapper.
.pth files add directories to your sys.path, so if you want to be able to 'import MySQLdb', then the directory containing MySQLdb has to be in the path. The only way around it that I see is to create some other directory, something like c:\\python27\\lib\\site-packages\\export\\
add it to your .pth file, and put inside a link to MySQLdb, like
mklink /D c:\\python27\\lib\\site-packages\\export\\MySQLdb c:\\python27\\lib\\site-packages\\MySQLdb
After way too much wasted time I've become convinced it is too hard to get mysqldb into a virtualenv with symbolic links on windows. However it is possible to fix it like so:
xcopy c:\python27\lib\site-packages\MySQLdb c:\Python\VirtualENV\lib\site-packages\MySQLdb /s/e
And tell it that this is a directory (not a file)
xcopy c:\python27\lib\site-packages\MySQL_python-1.2.3-py2.7.egg-info c:\Python\VirtualENV\lib\site-packages\ MySQL_python-1.2.3-py2.7.egg-info /s/e
And tell it that this is a directory (not a file)
copy c:\\python27\\lib\\site-packages_mysql*.* c:\\Python\\VirtualENV\\lib\\site-packages
You may at some point have to deal with 1.2.3 being something else, and of course VirtualENV is the virtualENV you need the support in.
You can get the mysql stuff from this link.
http://www.codegood.com/archives/129
Part of the problem comes from the fact that not all the mysql files are in the mysql directories. If they were, then a couple of symbolic links would work, but they aren't and it isn't worth fixing for windows.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.