LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Python extension module installed in /usr/local/lib[64]/python[2.7|3.x]/site-packages not found (https://www.linuxquestions.org/questions/slackware-14/python-extension-module-installed-in-usr-local-lib%5B64%5D-python%5B2-7%7C3-x%5D-site-packages-not-found-4175609661/)

Nate_KS 07-11-2017 03:48 PM

Python extension module installed in /usr/local/lib[64]/python[2.7|3.x]/site-packages not found
 
I am part of a team that develops and maintains a C library that is built using GNU Autotools with various language bindings generated by SWIG including Python. When I do local builds for testing, make install puts everything under the /usr/local hierarchy which keeps it nicely separated from the Slackware system hierarchy.

I am just getting started using Slackware64 Current as a daily runner on my laptop and I did a compile and install of the library with Python language bindings and could not import the extension module. Checking sys.path from the Python interpreter showed no paths into the /usr/local hierarchy.

Previously I had developed on Debian based systems and the extension module installed into the /usr/local hierarchy "just worked", so this a new twist for me.

I'm aware that this can be resolved at run time by juggling the PYTHONPATH environment variable, but that is going to get tedious quickly when jumping between Python 2.7 and 3.6. I'm sure there are ways to deal with this at the script level as well, but I would like to have a solution that I could set in this system so that either version Python can find its relevant extension module.

As I understand it, this does not affect the SBo build scripts of the same library that I maintain, just the source builds installed via GNU Autotools.

TIA

TommyC7 07-11-2017 10:06 PM

Hi there!

I have 2 solutions for this which might work:

1) Define PYTHONPATH in an /etc/profile.d script and then export it so you don't have to worry about it (at runtime either).

2) Since sys.path is just a list (in the python sense), you can simply append the respective directory with
Code:

sys.path.append("/path/to/whereever")
# Or perhaps you'd like to check first: if "/path/to/whereever" not in sys.path: sys.path.append("/path/to/whereever")

I believe both solutions should work for both python2 and python3.


All times are GMT -5. The time now is 01:19 AM.