From: Hartmut Goebel <h.goebel@crazy-compilers.com>
To: Guix-devel <guix-devel@gnu.org>
Cc: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Subject: Anomalies in Python search-path (was: [PATCH] Update python-pip to 9.0.1)
Date: Sat, 14 Jan 2017 22:02:20 +0100 [thread overview]
Message-ID: <6bfab194-5796-733f-75dd-f0214e3410f8@crazy-compilers.com> (raw)
In-Reply-To: <8737gw2fqw.fsf@gmail.com>
Am 06.01.2017 um 19:41 schrieb Maxim Cournoyer:
> One thing which I discovered while testing pip on Guix was that
> depending on how you use Python on Guix the PYTHONPATH differs:
I analysed this problem and found set we have another serious problem
here. But good news: There is an easy solution for both problems.
Result of the analysis (as explained below): We must not extend
PYTHONPATH for adding the profile's site-packages directory.
Proposed solution: The standard library module "site" already contains a
place where we can hook in:
# Prefixes for site-packages; add additional prefixes like /usr/local
here
PREFIXES = [sys.prefix, sys.exec_prefix]
So we simply prepend $GUIX_ENVIRONMENT to this list:
PREFIXES = [os.path.expandvar(GUIX_ENVIRONMENT), sys.prefix,
sys.exec_prefix]
Prepending to speed up searches, since within an environment almost all
site-packages will end in GUIX_ENVIRONMENT. There is no need to check if
$GUIX_ENVIRONMENT is set, since if it is not, it will be left unchanged
and the non-existing path will be skipped out automatically
This would solve both the problem Maxim described and the problem
described below, since the Guix site-packages behave exactly like any
other global site-packages directory.
When following this proposal, we *may* even remove some "wrapping" stuff
in the python-build-system. But this has to be investigated first.
Analysis (proof see below):
The python interpreter was two command line options, which are rarely
used, though:
-E ignores environment variables, esp. PYTHONPATH
-S Disable the import of the module site and the site-dependent
manipulations of sys.path.
This means:
a) When passing -E, the Guix environment's site-packages are ignored
(together with PYTHONPATH), while they should not.
b) When passing -S, the Guix environment's site-packages should be
ignored, but is not (since it is specified in $PYTHONPATH, which is not
ignored)
Conclusion: We should must not use PYTHONPATH to specify the Guix's
environment's site-package directory.
Analysis details:
(guix)$ which python3
/gnu/store/zcnb…-profile/bin/python3
Without any options:
-> /home/USER/.local/lib/python3.5/site-packages and
/gnu/store/zcnb…-profile/lib/python3.5/site-packages
should be in sys.path
(base)$ python3 -c 'import sys ; print("\n".join(sys.path))'
/usr/lib64/python34.zip
/usr/lib64/python3.4
/usr/lib64/python3.4/plat-linux
/usr/lib64/python3.4/lib-dynload
/home/USER/.local/lib/python3.4/site-packages
/usr/lib64/python3.4/site-packages
/usr/lib/python3.4/site-packages
(guix)$ python3 -c 'import sys ; print("\n".join(sys.path))'
/gnu/store/zcnb…-profile/lib/python3.5/site-packages
/gnu/store/alk9…-python-3.5.2/lib/python35.zip
/gnu/store/alk9…-python-3.5.2/lib/python3.5
/gnu/store/alk9…-python-3.5.2/lib/python3.5/plat-linux
/gnu/store/alk9…-python-3.5.2/lib/python3.5/lib-dynload
/home/USER/.local/lib/python3.5/site-packages
/gnu/store/alk9…-python-3.5.2/lib/python3.5/site-packages
-E Ignore environment variables like PYTHONPATH and PYTHONHOME
that modify the behavior of the interpreter.
-> /home/USER/.local/lib/python3.5/site-packages and
/gnu/store/zcnb…-profile/lib/python3.5/site-packages
should be in sys.path
(base)$ python3 -E -c 'import sys ; print("\n".join(sys.path))'
/usr/lib64/python34.zip
/usr/lib64/python3.4
/usr/lib64/python3.4/plat-linux
/usr/lib64/python3.4/lib-dynload
/home/USER/.local/lib/python3.4/site-packages
/usr/lib64/python3.4/site-packages
/usr/lib/python3.4/site-packages
(guix)$ python3 -E -c 'import sys ; print("\n".join(sys.path))'
/gnu/store/alk9…-python-3.5.2/lib/python35.zip
/gnu/store/alk9…-python-3.5.2/lib/python3.5
/gnu/store/alk9…-python-3.5.2/lib/python3.5/plat-linux
/gnu/store/alk9…-python-3.5.2/lib/python3.5/lib-dynload
/home/USER/.local/lib/python3.5/site-packages
/gnu/store/alk9…-python-3.5.2/lib/python3.5/site-packages
-S = Disable the import of the module site and the site-dependent
manipulations of sys.path that it entails.
-> /home/USER/.local/lib/python3.5/site-packages and
/gnu/store/zcnb…-profile/lib/python3.5/site-packages
sould *not* be in sys.path
(base)$ python3 -S -c 'import sys ; print("\n".join(sys.path))'
/usr/lib64/python34.zip
/usr/lib64/python3.4/
/usr/lib64/python3.4/plat-linux
/usr/lib64/python3.4/lib-dynload
(guix)$ python3 -S -c 'import sys ; print("\n".join(sys.path))'
/gnu/store/zcnb…-profile/lib/python3.5/site-packages
/gnu/store/alk9…-python-3.5.2/lib/python35.zip
/gnu/store/alk9…-python-3.5.2/lib/python3.5/
/gnu/store/alk9…-python-3.5.2/lib/python3.5/plat-linux
/gnu/store/alk9…-python-3.5.2/lib/python3.5/lib-dynload
--
Regards
Hartmut Goebel
| Hartmut Goebel | h.goebel@crazy-compilers.com |
| www.crazy-compilers.com | compilers which you thought are impossible |
next prev parent reply other threads:[~2017-01-14 21:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-06 18:41 [PATCH] Update python-pip to 9.0.1 Maxim Cournoyer
2017-01-09 14:52 ` Ludovic Courtès
2017-01-12 16:44 ` Maxim Cournoyer
2017-01-14 17:43 ` Ludovic Courtès
2017-01-15 17:55 ` Anomalies in Python search-path (was: [PATCH] Update python-pip to 9.0.1) Maxim Cournoyer
2017-01-15 22:10 ` Anomalies in Python search-path Ludovic Courtès
2017-01-16 9:30 ` Hartmut Goebel
2017-01-19 11:48 ` Ludovic Courtès
2017-01-14 21:02 ` Hartmut Goebel [this message]
2017-01-15 19:23 ` Maxim Cournoyer
2017-01-16 9:23 ` Hartmut Goebel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6bfab194-5796-733f-75dd-f0214e3410f8@crazy-compilers.com \
--to=h.goebel@crazy-compilers.com \
--cc=guix-devel@gnu.org \
--cc=maxim.cournoyer@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).