Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

System-wide module path

25 views
Skip to first unread message

Rob Gaddi

unread,
Oct 24, 2016, 7:50:18 PM10/24/16
to
On a Linux (Ubuntu) system, with no concerns for Python < 3.4, how do I
a) Add a directory to the system-wide (rather than per-user) module
path?
b) Tell pip that I would like to install a given module to there.

What's going on is that we're trying to set up an internal software
distribution system to make sure that internally-written software gets
installed on a bunch of identical machines. The easiest mechanism to
work with in all of this is a single directory on the server that can
simply be rsync'd to all of the target machines. So if I could do my
installs to /usr/highland/python3.4/site-packages, and put all the
executable stubs that pip creates into /usr/highland/bin, then I can
just rsync all of /usr/highland.

--
Rob Gaddi, Highland Technology -- www.highlandtechnology.com

Email address domain is currently out of order. See above to fix.

Zachary Ware

unread,
Oct 25, 2016, 12:20:13 AM10/25/16
to
On Mon, Oct 24, 2016 at 6:49 PM, Rob Gaddi
<rga...@highlandtechnology.invalid> wrote:
> On a Linux (Ubuntu) system, with no concerns for Python < 3.4, how do I
> a) Add a directory to the system-wide (rather than per-user) module
> path?

This is the trickier part. There are a couple of ways to do it, but
which is better is a matter of some debate (at least in my head). The
first option is to stick a `.pth` file in the regular site-packages
directory that points to /usr/highland/lib/python3.4/site-packages.
Another option is to set PYTHONPATH; this is one of the very few
exceptions to the rule that you never want to permanently set
PYTHONPATH. The main differences between the two options are which
end of sys.path the directory is added to, and whether it's added when
the -S interpreter option is used (say, by system utilities). The
`.pth` option is cleaner and safer, but `.pth` files just feel icky.

> b) Tell pip that I would like to install a given module to there.

Use the --prefix option: `pip install --prefix /usr/highland/
alembic`. This tells pip to install the package(s) as though Python
was installed at /usr/highland/, so libraries go in
/usr/highland/lib/python3.4/site-packages and executable stubs go in
/usr/highland/bin/.

Hope this helps,
--
Zach
0 new messages