I am fairly new to Python and therefore my error-solving skills are not much yet developed. I am using Python within a geoprocessing script which is supposed to use ogr (reading/writing shp) and shapely (geometry processing) to dissolve a shapefile with n polygons in it.

To accomplish that step I need the function "cascaded_union" in the shapely.ops module. As soon as I have the import in my script from shapely.ops import cascaded_union I am getting an Error even when I don't use the function anywhere in the script yet. That is why I suppose that this is not a usage rather than a installation/configuration error.

  • running an Ubuntu 12.04.3 LTS
  • Eclipse with PyDev
  • installed shapely via Ubuntu repositories
  • included path: /usr/lib/python2.7/dist-packages/shapely

Error Message:

Original exception was:
Traceback (most recent call last):
  File "/home/user/workspace/testproject/dissolve.py", line 3, in <module>
    from shapely.ops import cascaded_union
  File "/usr/lib/python2.7/dist-packages/shapely/ops.py", line 6, in <module>
    from shapely.geos import lgeos
  File "/usr/lib/python2.7/dist-packages/shapely/geos.py", line 12, in <module>
    from ctypes.util import find_library
  File "/usr/lib/python2.7/ctypes/util.py", line 89, in <module>
    import re, tempfile, errno
  File "/usr/lib/python2.7/tempfile.py", line 34, in <module>
    from random import Random as _Random
  File "/usr/lib/python2.7/dist-packages/numpy/random/__init__.py", line 90, in <module>
    ranf = random = sample = random_sample
NameError: name 'random_sample' is not defined

Content of dissolve.py:

from shapely.ops import cascaded_union

The auto completion of the import works. So the packages are recognized I guess.

I am thankful for any help/suggestions.

  • Isn't the problem comin from the random module ? – radouxju Jan 10 '14 at 13:52

The problem isn't shapely, it's numpy. Uninstall numpy and try again. Also, check to make sure that you're not using code like "from numpy import *" in your program. This will lead to conflicts between the stdlib random module needed by ctypes and numpy's random module.

| improve this answer | |
  • but I need numpy within another part of my work. How can I solve this issue then? Any possibilities? – andehhh Jan 13 '14 at 8:50
  • are you using "from numpy import *"? don't do that. see stackoverflow.com/questions/7855845/…. – sgillies Jan 13 '14 at 16:48
  • no I don't. I use numpy in another part of the script (different file) with "import numpy" – andehhh Jan 14 '14 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.