Python looks for several different files for any given import , including a directory by that name and containing the __init__.py , .so file for clean Python source modules and .pyc files that can be used even if .py is deleted.
Run strace -o trace_output.txt python to see how it works. Partial example for import md5 :
stat("/usr/lib/python2.7/md5", 0x7fff81ff16d0) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.7/md5.x86_64-linux-gnu.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.7/md5.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.7/md5module.so", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/lib/python2.7/md5.py", O_RDONLY) = 3
In my setup, it is actually looking for:
~/.local/lib/python2.7//usr/local/lib/python2.7/dist-packages/usr/lib/python2.7/dist-packages/usr/lib/python2.7/
Within each directory, a stat invocation pattern to search for a directory that searches for .so files, then .py .
For more information on writing a purely native python module, see here: https://docs.python.org/2/extending/index.html
source share