I'm using the mathematical modelling package coopr.pyomo successfully in both script files and interactively on the ipython console. However, if I try a simple import coopr.pyomo in an IPython notebook started by ipython notebook, I get the following error message:
ImportError Traceback (most recent call last)
<ipython-input-1-ff8219fceacd> in <module>()
----> 1 import coopr.pyomo
ImportError: No module named pyomo
Other imports (both buitlins and custom packages) work without trouble. Any ideas where to look for a cause?
Environment: Python 2.7 (32 bit) on Windows 7, IPython 0.13.2, Coopr release 3.2.6148.
Edit: more diagnostics
Indeed, coopr can be imported, yet has not __file__ attribute. If I display __dict__, I get the correct path:
{'__name__': 'coopr',
'data': <module 'coopr.data' (built-in)>,
'__doc__': None,
'__path__': ['C:\\Python27\\lib\\site-packages\\coopr']}
If I browse in that directory, I find that all submodules (e.g. coopr.pyomo) are located in the src subdirectory. data seems to be a spurious directory with some test (test_baselines.py, test_perf.py) and example (diet1.py) files.
Edit #2: it's getting closer (I think)
The issue seems to be caused by the peculiar way how the windows installer of Coopr works. According to the Installation Notes, Coopr sits encapsulated in its own virtual sandbox. This is underlined by its default installation directory suggestion CH := C:/Packages/Coopr. Last time, I ignored this sign and simply installed it to Python's site-packages folder. Now, for testing, I re-installed Coopr to this external directory. Coopr/Pyomo still can be successfully imported from within a (I)Python session, as sys.path is extended by all the subdirectories of the CH/src/ directory.
However, these subdirectories look different from other packages I am used to. For example, src/coopr.pyomo only contains a setup.py, while __init__.py sits in CH/src/coopr.pyomo/coopr/pyomo. While IPython seems to be able to find the packages, IPython notebook -- although the search path is identical -- seems to get confused by the way the packages are organised.
site-packagesdirectory, not by runningpython setup.py install. - user707650