0

In my Python installation for python3.7, ctypes is installed. For example, __init__.py is located in: /usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py. This makes sense to me.

Note: my OS is MacOS Mojave, 10.14.3.

ctypes constantly refers to _ctypes. I use PyCharm, and when I control-left click on _ctypes, it takes me to: /Users/myuser/Library/Caches/PyCharmCE2018.3/python_stubs/-1199943126/_ctypes.py.

Why is _ctypes.py in this random folder, and not in the folder installed with Python 3.7?

1 Answer 1

1

There's no real _ctypes.py. That file you're seeing is something PyCharm created so it could show you fake source code. It's in that weird place because it's fake. I don't know why PyCharm does that.

The real source code for _ctypes is in C, and it doesn't make it into your Python distribution. You can see it in the CPython repository under the Modules/_ctypes folder. You can see where the compiled file for _ctypes is by importing _ctypes and inspecting _ctypes.__file__, but it's compiled, so for most purposes, you'll want to look at the source code instead.

Sign up to request clarification or add additional context in comments.

3 Comments

Here is info on PyCharm and python_stubs: stackoverflow.com/questions/24266114/…
Also @user2357112, thank you for sharing the link to GitHub. Where do you think I can find cpython/Modules/_ctypes folder on my local machine? I don't see it in site-packages and a search of my Mac via Finder doesn't yield anything
@IntrastellarExplorer: Like I said, it's probably not on your local machine at all.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.