Python Search Path

Home » CentOS » Python Search Path
CentOS 3 Comments


Working on a project to create clean spec files for libbitcoin for CentOS 7 (and eventually I want them to work in Fedora 25+ too)

These spec files must work with the user defines an alternate %{_prefix}
before building them.

This means that python components would be installed in /opt/libbitcoin
(or whatever) instead of in /usr so %{python2_sitelib} and
%{python2_sitearch} no longer would apply.

sys.path.append looks like the way to tell python about a new path to look for stuff, but I’m guessing there are guidelines somewhere for how that is suppose to properly done from within spec files.

Unfortunately I can’t find them, and search engines are getting harder and harder to use to find technical related information, always changing my query and showing me completely unrelated results.

Anyway I didn’t see anything in the Fedora packaging guidelines for python, that seems to be targeting a prefix of /usr

Thanks for any links or suggestions.

3 thoughts on - Python Search Path

  • So you want to build something independent of the system python? Is virtualenv and / or anaconda interesting here?

  • I want to create RPM spec file that lets the user build the RPM with an alternate prefix – e.g.

    rpmbuild -D ‘_prefix /opt/whatever’ -bb package.spec

    That results in in the python files being placed in

    /opt/whatever/lib/pythonN/site-packages and

    Those directories are outside of the default python search path.

    I could leave it up to the user to add them, but its nice when installing a package just works (hence why we can put files in
    /etc/ for example) without the user needing to fuss too much.

    When the user builds with a different prefix, there likely will be several different packages that put python stuff in that prefix, so a meta package they require that adds to the search path is what I am thinking, that both adds to the python when installed and removes it from the python search path when removed.

  • Found solution, it was rather easy – just put a .pth in the “official”
    site-packages containing the full path to the directory being added.