Enthought Canopy Basemap Import Failure - enthought

I'm running Enthought Canopy Version 1.5.2730 with Basemap version 1.0.7-5 and pyproj version 1.9.3-1 installed on a Mac running OS X 10.9.5. When I try to import basemap I get the following error message.
from mpl_toolkits.basemap import Basemap
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-5e6824321d57> in <module>()
----> 1 from mpl_toolkits.basemap import Basemap
/Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py in <module>()
28 from matplotlib.lines import Line2D
29 from matplotlib.transforms import Bbox
---> 30 from mpl_toolkits.basemap import pyproj
31 from mpl_toolkits.axes_grid1 import make_axes_locatable
32 from matplotlib.image import imread
ImportError: cannot import name pyproj
If I try to import pyproj directly I get the following error mesage
ImportError Traceback (most recent call last)
<ipython-input-1-0cc08144b629> in <module>()
----> 1 from mpl_toolkits.basemap import pyproj
/Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/mpl_toolkits/basemap/__init__.py in <module>()
35 import numpy as np
36 import numpy.ma as ma
---> 37 import _geoslib
38 import functools
39
ImportError: dlopen(/Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-package /_geoslib.so, 2): Library not loaded: #rpath/lib/libgeos_c.1.dylib
Referenced from: /Users/wiltbemj/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/_geoslib.so
Reason: image not found
I've tried uninstalling and reinstalling the packages with no success. The missing dylib is on machine in the /opt/local/lib directory. Not sure if it is path problem or something more complicated. Any hints as to how to begin debugging the issue are greatly appreciated.

IIUC, this is due to some libraries that were formerly supplied by basemap, and now are supplied by geos, that were inappropriately removed by updating basemap.
To fix it, open a Canopy Terminal (from the Canopy Tools menu) and type:
enpkg --remove geos
enpkg geos

Related

ImportError: No module named 'bson.objectid' [duplicate]

I have currently django-mongodb-engine 0.4.0 version installed on my Mac OS X 10.6.8 and weirdly encountered an interesting error while importing the 'compiler' module:
>> from django_mongodb_engine import compiler
and I got the following error:
ImportError Traceback (most recent call last)
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_extensions/management/commands/shell_plus.pyc in <module>()
----> 1 from django_mongodb_engine import compiler
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django_mongodb_engine/compiler.pyc in <module>()
15 from pymongo.errors import PyMongoError
16 from pymongo import ASCENDING, DESCENDING
---> 17 from pymongo.objectid import ObjectId, InvalidId
18
19 from djangotoolbox.db.basecompiler import NonrelQuery, NonrelCompiler, \
ImportError: No module named objectid
I installed the package via pip command and all the dependencies like pymongo, djangotoolbox have been installed along with it. The pip command I'd used is this:
>> sudo env ARCHFLAGS='-arch i386 -arch x86_64' pip install --upgrade django-mongodb-engine
The current versions of the related packages are:
>> pip freeze | grep mongo
django-mongodb-engine==0.4.0
pymongo==2.2
I suspect the django_mongodb_engine package is broken because ObjectId is not imported inside pymongo anymore. Instead, it belongs to bson module.
What are your suggestions to fix this problem? Should I clone the django-mongodb-engine project and fix on github?
I've ran into something similar, for me the problem was this line:
from pymongo.objectid import ObjectId
The call seems to work in versions of PyMongo < 2.2
In pymongo 2.2 the call to import objectid is:
from bson.objectid import ObjectId
Looks like they're already aware (see this pull request), but no one's created a pull request against the develop branch yet. You could try fixing that and submit a new pull request.
I tried to install bson with pip directly. Uninstall, and install pymongo instead and the error didnt reappear.
I'm on Python3 (in 2017) and found that the following works:
from pymongo import MongoClient
from bson import ObjectId

scipy ImportError: dlopen no suitable image found in Python 3

I have python 3.6, Mac OS X El Capitan.
I installed scipy by pip install scipy. But when I import scipy, I get the following error:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/init.py in ()
116 del _NumpyVersion
117
--> 118 from scipy._lib._ccallback import LowLevelCallable
119
120 from scipy._lib._testutils import PytestTester
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/_lib/_ccallback.py in ()
----> 1 from . import _ccallback_c
2
3 import ctypes
4
5 PyCFuncPtr = ctypes.CFUNCTYPE(ctypes.c_void_p).bases[0]
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/_lib/_ccallback_c.cpython-36m-darwin.so, 2): no suitable image found. Did find:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/scipy/_lib/_ccallback_c.cpython-36m-darwin.so: mach-o, but wrong architecture
I don't get this error in Python2.
Looks like I am the only one on earth to have this issue. Fortunately, I got it to work with endless attempts. In case someone in the future gets the same error, you can try this:python -m pip install scipy. I have no idea why pip install scipy doesn't work.
What I did find on MacOS 10.14.2 is that I had installed Scipy 1.1. After executing python -m pip install scipy I got Scipy 1.2 and get rid of "ImportError: dlopen".

failed to import numpy as np when I worked with jupyter notebook

In Jupyter, there is an ImportError:
import numpy as np
ImportError Traceback (most recent call last)
ipython-input-1-4ee716103900 in module()
----> 1 import numpy as np
ImportError: No mudule named numpy
But in Python, there is no error:
import numpy as np
Usually this happens because your python is one Python environment and whatever you're running your notebook with is another. Try running import sys; sys.executable in both environments and seeing whether or not they match. If they don't, that's your problem: whatever jupyter is running in is borrowing numpy from the root environment.
For ubunutu environment
in jupyter, run:
import sys; sys.executable
This will display the python location eg
/home/paul/notepad_vm/notepad_vm/bin/python
switch to bash shell
cd /home/paul/notepad_vm/notepad_vm/bin/python
./pip install numpy
switch back to Jupyter, run:
import numpy as np

Shutil cannot import WindowsError on windows

I've observed that shutil fails to import WindowsError on our windows 7 systems:
from shutil import WindowsError
File <file>, line <no>, in <module>
from shutil import WindowsError
ImportError: cannot import name WindowsError
The same statement works absolutely fine on linux. Has anyone else come across it too? Do you know how I could fix it?
Python version: 2.6.7
Linux OS: Centos 6.3
Windows OS: Windows 7 Professional x64
Got a solution from the python bug tracker:
http://bugs.python.org/issue18525
This is an implementation artifact and would not be fixed. The import statement such as above are a wrong usage. The correct usage being(if necessary):
try:
WindowsError
except NameError:
WindowsError = None

Enthought Canopy 64bit on OSX: import pyglet.gl failure

Retaining question for posterity; see workaround in edit
The Pyglet package comes installed at base and isn't removable. Using the current fully updated version 1.1.4 of Pyglet, I get repeatable errors related to importing the item pyglet.gl.gl_info; for instance, upon attempting to create a pyglet.window.Window(), upon trying to import pyglet.gl, or upon attempting to import pygarrayimage via from pygarrayimage.arrayimage import ArrayInterfaceImage.
In all such cases the relevant traceback ends with the uninformative message:
/Users/[username]/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/pyglet/image/__init__.py in <module>()
142
143 from pyglet import gl
--> 144 from pyglet.gl import *
145 from pyglet.gl import gl_info
146 from pyglet import graphics
/Users/[username]/Library/Enthought/Canopy_64bit/System/lib/python2.7/site-packages/pyglet/gl/__init__.py in <module>()
102 from pyglet.gl.glext_arb import *
103 from pyglet.gl.glext_missing import *
--> 104 from pyglet.gl import gl_info
105
106 import sys as _sys
ImportError: cannot import name gl_info
I am using OSX 10.6.8 on an Intel processor, with Canopy 64-bit, and these are 100% repeatable.
Given the traceback one might assume gl_info mistakenly isn't included, but this isn't the case. dir(pyglet.gl.gl_info) can successfully be run.
Edit: Solved this problem.
Pyglet 1.1.4 does not support 64-bit on OSX, so until Enthought packages a newer release of Pyglet in Canopy, here is a workaround for 64-bit OSX users.
Acquire source for any release of Pyglet 1.2alpha1 or beyond.
Extract source to your directory of choice.
Append this directory to the beginning of your PYTHONPATH environment variable, in both ~/.bash_profile (for terminal shells) and /etc/launchd.conf (for GUI processes) with a line similar to: export PYTHONPATH=/Users/[username]/src/pyglet-1.2alpha1:$PYTHONPATH
Run this bash command in an unrelated directory and confirm the path printed leads to your 1.2alpha1 source directory: $ python -c "import pyglet; print pyglet.__path__[0]"
If you don't wish to modify your bash_profile, you can simply do the following:
Extract latest Pyglet source to your directory of choice and cd to that directory (it should contain a setup.py file).
Use Canopy's Python to install Pyglet by doing the following (on Mac 64 bit):
~/Library/Enthought/Canopy_64bit/User/bin/python setup.py install
The location of Canopy's Python for different platforms is listed here:
https://support.enthought.com/entries/23646538-Make-Canopy-s-Python-be-your-default-Python-i-e-on-the-PATH-