I'm currently using Python 3.7 and Pycharm for my work. Recently I got a code that is done at Python2.7 and it includes a library named 'ctypes.'

First I tried to download it through pip by Ctrl+Alt+S -> search 'ctypes' -> install. But it gave me an error message that

"Excuted command : pip install ctypes"
"Error occured : Non-zero exit code (1)"
"could not find a version that satisfies the requirement ctypes"

then I tried to install it through a .tar.gz file.

I got ctypes-1.0.2.tar.gz from the web and through cmd, I tried 'python setup.py', but I got an error message that

"ctypes %s requires Python 2.3 or better" % _version_ 

I have no idea about this and I'm guessing that ctypes isn't fitting on Python3.7

Anyone have some ideas or a solution? If it doesn't work on Python3.7, is there any recommendations that can replace ctypes?

  • 1
    Python 2.7 and 3.7 are substantially different and if your code was written for version 2 python then you would be better off downloading the latest version of python 2.7. Otherwise you will need to convert the code from python 2 to python 3. There are many articles describing the process online. Ctypes is a built-in part of python 3.
    – Mokubai
    Jan 9, 2019 at 8:21

2 Answers 2


I'm currently using Python 3.7 and Pycharm for my work. Recently I got a code that is done at Python2.7

You shouldn't use Python 3.7 to run code that was written for Python 2.x, unless you can port that code to Python 3, or you know that it works fine. There are some caveats, and it depends on what the functionality of that code is. In some cases it might be very time consuming to convert it. 2to3 might help here.

So, depending on your use case, you may want to keep a legacy version of Python 2.7 around on your system to run that particular code, but note that Python 2.x will not get any (security) updates anymore, so you're better off using Python 3 from now on.

Try running the code in Python 3.7 and see if it works.

and it includes a library named 'ctypes.'

This is included by default in Python, so you don't need to install anything. Assuming you have the correct Python 2.7 interpreter and all other required packages, the code should just run fine as-is.

If the person who wrote the code was doing a good job, he or she should have left a README and/or a requirements.txt file or something similar that would specify which other packages or libraries are needed to run it.


This S.O question has an answer which says

You don't need to install ctypes at all; it is part of the Python standard library, as of Python 2.5 onwards. See the module documentation.

which was provided by @MartijnPieters who has over 700k rep and so, presumably, knows what he is talking about.

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.