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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With