|"""IPython startup script to detect and inject VIRTUAL_ENV's site-packages dirs.|
|IPython can detect virtualenv's path and injects it's site-packages dirs into sys.path.|
|But it can go wrong if IPython's python version differs from VIRTUAL_ENV's.|
|This module fixes it looking for the actual directories. We use only old stdlib|
|resources so it can work with as many Python versions as possible.|
|Author: Henrique Bastos <email@example.com>|
|from warnings import warn|
|virtualenv = os.environ.get('VIRTUAL_ENV')|
|version = os.listdir(os.path.join(virtualenv, 'lib'))|
|site_packages = os.path.join(virtualenv, 'lib', version, 'site-packages')|
|lib_dynload = os.path.join(virtualenv, 'lib', version, 'lib-dynload')|
|if not (os.path.exists(site_packages) and os.path.exists(lib_dynload)):|
|msg = 'Virtualenv site-packages discovery went wrong for %r' % repr([site_packages, lib_dynload])|
|i = sys.path.index("") + 1|
|i = 0|
I don't know if there's a way to send pull requests for a gist. Anyway, there's a suggestion below.
Keeping the default Python behavior to search for modules in current directory first, change lines 34 and 35 to this:
It allows local custom modules override their version even inside the virtualenv.
Good work. Keep walking.
I was following your Medium post to get something setup on my machine. I started running into some issues with packages that used
It turned out that by the time that the script in this gist was called,
Thus, the solution that I found (not sure how "correct" it is...) is to:
along with the
This simply looks for anything that has 'egg-link' in the name, then opens the file and adds the first line to the path. No idea if you could have an edge case in which there could be multiple paths or lines in the egg-link, but this works for my needs.