Discussion:
[Python.NET] importing eggs. does pythonnet not use respect the easy-install.pth file?
John Burkhart
2013-08-23 10:51:14 UTC
Permalink
Hello,

I have a pythonnet installation that works fine for the most part. However,
whenever I try to import a module that was built with easy_install, I have
to explicitly add the full egg path to the sys.path variable. Does
pythonnet not respect the easy-install.pth file?

[code]
import south
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named south
import sys
sys.path.append(r'C:\Python27\lib\site-packages\south-0.8.2-py2.7.egg')
import south
import openpyxl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named openpyxl
sys.path.append(r'C:\Python27\lib\site-packages\openpyxl-1.6.1-py2.7.egg')
import openpyxl
[/code]


My easy-install.pth file contains:

[code]
import sys; sys.__plen = len(sys.path)
./python_distutils_extra-2.37-py2.7.egg
./openpyxl-1.6.1-py2.7.egg
./south-0.8.2-py2.7.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert =
p+len(new)
[/code]
John Burkhart
2013-08-23 11:09:02 UTC
Permalink
This is my current work-around

## Seems to be a required hack for pythonnet
if 'pythonnet' in sys.executable:
try:
import site
site.addsitedir(r'C:\Python27\lib\site-packages')
except:
print sys.path
Post by John Burkhart
Hello,
I have a pythonnet installation that works fine for the most part.
However, whenever I try to import a module that was built with
easy_install, I have to explicitly add the full egg path to the sys.path
variable. Does pythonnet not respect the easy-install.pth file?
[code]
import south
File "<stdin>", line 1, in <module>
ImportError: No module named south
import sys
sys.path.append(r'C:\Python27\lib\site-packages\south-0.8.2-py2.7.egg')
import south
import openpyxl
File "<stdin>", line 1, in <module>
ImportError: No module named openpyxl
sys.path.append(r'C:\Python27\lib\site-packages\openpyxl-1.6.1-py2.7.egg')
import openpyxl
[/code]
[code]
import sys; sys.__plen = len(sys.path)
./python_distutils_extra-2.37-py2.7.egg
./openpyxl-1.6.1-py2.7.egg
./south-0.8.2-py2.7.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:];
p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert =
p+len(new)
[/code]
Loading...