简体   繁体   中英

How to import a module installed in site-packages

I have updated this to change the question how can I import from an .so file, for which there is already a named .py file front end.

On CentOS 6.6, I have Python 2.6.6 installed, and am I am trying to install InformixDB-2.5.

The python setup.py build_ext command returns a few warnings, but the gcc step completes without errors.

As root, the python setup.py install command completes without errors.

My problem is when I run Python and enter import informixdb , I get a module not found error

I have read this , and already have an informixdb.py in site-packages along with _informixdb.so . If I invoke Python from that directory and import informixdb , I get no error. I'm just not sure which environment variable to set to pick this up, or if I should symlink to this, but do not know what to symlink.

This is the output of python setup.py install

running install
running build
running build_py
running build_ext
running install_lib
running install_egg_info
Removing /usr/lib/python2.6/site-packages/InformixDB-2.5-py2.6.egg-info
Writing /usr/lib/python2.6/site-packages/InformixDB-2.5-py2.6.egg-info

Here is the error

[dbadmin@bucky InformixDB-2.5]$ python informixdb.py
Traceback (most recent call last):
  File "informixdb.py", line 146, in <module>
    from _informixdb import *
ImportError: No module named _informixdb

First off, in order to isolate the problem, don't invoke python or your script from the same directory where you built or from where you installed InformixDB. Instead, invoke it from wherever your application lives. From there, see what happens if you try "import informixdb". If python complains that it can't find "informixdb" (without underscore in the name), your Python path is messed up, and you need to fix your Python path to include the location where InformixDB was installed.

If python complains that it can't import "_informixdb" (with underscore), verify that _informixdb.so is in the same location as informixdb.py and that the permissions are correct on that file. If it is, the problem is most likely that the dynamic linker can't find the Informix client runtime libraries.

To check whether the latter is the problem, run the command "ldd /path/to/_informixdb.so" and look at the output. It should look something like this:

carsten@haese:~$ ldd /usr/local/lib/python2.7/dist-packages/_informixdb.so
    linux-gate.so.1 =>  (0x00f47000)
    libifsql.so => /opt/informix/lib/esql/libifsql.so (0x001d9000)
    libifasf.so => /opt/informix/lib/libifasf.so (0x00999000)
    libifgen.so => /opt/informix/lib/esql/libifgen.so (0x00110000)
    libifos.so => /opt/informix/lib/esql/libifos.so (0x0039f000)
    libifgls.so => /opt/informix/lib/esql/libifgls.so (0x0061d000)
    libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0x006c5000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0x00be8000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0x00342000)
    libdl.so.2 => /lib/i386-linux-gnu/libdl.so.2 (0x001b1000)
    libcrypt.so.1 => /lib/i386-linux-gnu/libcrypt.so.1 (0x00220000)
    /lib/ld-linux.so.2 (0x0016a000)

If the ldd command indicates that any of the libifXXX libraries are not found, that's your problem and you'll need to tell the dynamic linker where the Informix libraries are, for example by setting the LD_LIBRARY_PATH environment variable appropriately or by adding it to etc/ld.so.conf.d in some fashion and running ldconfig.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM