Opened 12 years ago

Closed 3 years ago

#267 closed defect (outdated)

ctypes version conflict with numpy

Reported by: davidfawcett Owned by: osgeo4w-dev@…
Priority: major Component: Package
Version: Keywords: python ctypes numpy
Cc:

Description (last modified by maphew)

When I try to import numpy, I get the below error. It appears that it looks for ctypeslib.py in the right spot, but then it goes to the path for my 'system python', which is Python 2.5 for ctypes\init.py.

I just ran the OSGeo4W installer to update all of the packages.

GDAL 1.8.1, released 2011/07/09

H:\>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\numpy\__init__.py", line 154,
 in <module>
    import ctypeslib
  File "C:\OSGeo4W\apps\Python27\lib\site-packages\numpy\ctypeslib.py", line 60,
 in <module>
    import ctypes
  File "D:\Python25\lib\ctypes\__init__.py", line 20, in <module>
    raise Exception, ("Version number mismatch", __version__, _ctypes_version)
Exception: ('Version number mismatch', '1.0.2', '1.1.0')
>>>

Change History (4)

comment:1 by maphew, 12 years ago

Description: modified (diff)

David, the system python variables needs to be removed from the environment before starting the o4w python. To see the existing python env, open a command prompt and type:

set |findstr /i "python"

If you see something like the below you'll have a conflict with the Osgeo4W python:

Path=C:\Python26;C:\Python26\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\sysWOW64
PYTHONHOME=C:\Python26
PYTHONPATH=C:\Python26;C:\Python26\Lib;C:\Python26\DLLs

To fix this you'll need to remove the existing python settings from the system default ([Winkey]-[pause/break] > Advanced > Environment) or take care to always start python from inside a new shell which resets those variables, e.g. from a batch file:

@echo off
set PYTHONHOME=
set PYTHONPATH=
set PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\sysWOW64;
call c:\osgeo4w\osgeo4w.bat

comment:2 by davidfawcett, 12 years ago

Thanks maphew.

I wasn't able to get it to work by following your directions for resetting the python system vars.

I am running into errors with QGIS pluggin installs that appear to be based on the same issue.

I think that this is a pretty critical issue. If we want people who are new to OpenSource Geospatial apps to try them out, we need to figure out how to make them play well with their existing system setups. I have always like OSGEO4W and MS4W because they installed in a fairly separate and self-contained way.

Thanks,

David.

comment:3 by maphew, 12 years ago

I can't replicate the error exactly, but I came close by opening a command shell via Osgeo4w.bat and then:

O:\> set PYTHONPATH=C:\Python25;C:\Python25\Lib;C:\Python25\DLLs

O:\> python test-ticket247.py
:: contains "import ctypes"

Traceback (most recent call last):
  File "test-ticket247.py", line 1, in <module>
    import ctypes
  File "C:\Python25\Lib\ctypes\__init__.py", line 10, in <module>
    from _ctypes import Union, Structure, Array
ImportError: Module use of python25.dll conflicts with this version of Python.

O:\> python --version
Python 2.7.2

This computer (Win7 x64) has python 2.5 (+ numpy) and 2.7 installed from python.org using the standard .msi's, and 2.7 via Osgeo4W; all pythons are 32bit. I use the Osgeo4w python most of the time.

It's clear something is allowing your python 2.5 environment to bleed over but I don't know what or where you might look next. I don't think it's coming from the osgeo4w side.

comment:4 by jef, 3 years ago

Resolution: outdated
Status: newclosed
Note: See TracTickets for help on using tickets.