In Python, the name of a module is usually the same as the name of the corresponding file, but I have a problem with a module for which it is not the case:
me@host:/usr/lib/python2.7/dist-packages/paraview$ ls vtkCommonCorePython*
vtkCommonCorePython.x86_64-linux-gnu.so
me@host:/usr/lib/python2.7/dist-packages/paraview$ python -c \
"import vtkCommonCorePython; print(vtkCommonCorePython.__file__)"
vtkCommonCorePython.x86_64-linux-gnu.so
How does it work?
My problem is that I try to use this module with another Python (/opt/python/2.7.9/bin/python) and it does not find the module:
me@host:/usr/lib/python2.7/dist-packages/paraview$ module load python/2.7.9
--- Loading module environment: python/2.7.9
------------------------------------------------
me@host:/usr/lib/python2.7/dist-packages/paraview$ python -c \
"import vtkCommonCorePython; print(vtkCommonCorePython.__file__)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named vtkCommonCorePython
Remark: Most of the files in /usr/lib/python2.7/lib-dynload
also end with x86_64-linux-gnu.so
while the files in /opt/python/2.7.9/lib/python2.7/lib-dynload
just end with .so
.
Update after cdarke's answer:
cdarke mentions the imp.get_suffixes
function, which returns a tuple with suffixes and their meaning for Python:
with /opt/python/2.7.9/bin/python
[('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1), ('.pyc', 'rb', 2)]
and with /usr/lib/python
[('.x86_64-linux-gnu.so', 'rb', 3), ('.so', 'rb', 3), ('module.so', 'rb', 3), ('.py', 'U', 1), ('.pyc', 'rb', 2)]
This difference explains why I get the error but then it does not seem that these suffixes are set in site.py
(as written by cdarke) and there is no function imp.set_suffixes
.
So to solve the problem I need to know how are set these suffixes.
Update 2
So it seems that the suffixes are encoded into a binary Python file, meaning that there is no way to modify that after the building of Python. So the cleanest way to solve the problem would be to rebuild the opt Python and thus to understand which options to give to configure
to obtain a Python multi-arch as the system Python under Debian Jessie.
Cdarke, thanks a lot for the help.