saurabh
saurabh

Reputation: 137

ctypes import not working on python 2.5

I am trying to import ctypes, and I am using Python 2.5.5 installed using macports (on Mac OS X 10.6).

I get an error saying "ImportError: No module named _ctypes" (see details below). As I understand it ctypes is supposed to come preinstalled for python 2.5. Any suggestions?

thanks, Saurabh

Error details:

$ python
Python 2.5.5 (r255:77872, Nov 30 2010, 00:05:47) 
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ctypes/\_\_init\_\_.py", line 10, in <module>
    from _ctypes import Union, Structure, Array
ImportError: No module named _ctypes

Update: I checked the /opt/local/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload directory based no Ned's reply. There is no _ctypes.so file, however the two related files that are there are:

-rwxr-xr-x  2 root  wheel  136176 Nov 30 00:07 _ctypes_failed.so
-rwxr-xr-x  2 root  wheel   26160 Nov 30 00:05 _ctypes_test.so

Does this mean I need to reinstall ctypes?

Update 2: Reinstalling python 2.5 solved the problem. Not quite sure what caused the original problem.

Upvotes: 5

Views: 3485

Answers (3)

Ned Deily
Ned Deily

Reputation: 85125

It might be a file permission problem. I don't have a MacPorts Python 2.5 installation handy but, based on a MacPorts Python 2.6, there should be a file something like this:

$ cd /opt/local/Library/Frameworks/Python.framework/Versions/2.5
$ cd ./lib/python2.5/lib-dynload/
$ ls -l _ctypes.so 
-rwxr-xr-x  2 root  wheel  151536 Oct  8 00:26 _ctypes.so*

If not, update your question with the results of an ls -l of the lib-dynload directory above.

Update: based on your additional information, the presence of _ctypes_failed.so indicates that the building of _ctypes failed during the build and installation of Python 2.5. Try reinstalling it with verbose mode to see what the failure is:

$ port sudo selfupdate
$ port -v upgrade --force python25

Upvotes: 1

Keith
Keith

Reputation: 43064

The latest Mac OS X ships with Python 2.6. Try using that instead of macports. Importing ctypes works already on my system.

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>>

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799520

Install libffi, then rebuild Python.

Upvotes: 0

Related Questions