From mboxrd@z Thu Jan 1 00:00:00 1970 From: Hartmut Goebel Subject: Re: PYTHONPATH woes Date: Thu, 22 Feb 2018 21:42:13 +0100 Message-ID: <1e1bc33b-8c4d-a99a-98e1-e53622518c01@crazy-compilers.com> References: <87371tqbyb.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="------------D18AC0E3A759A08D0AF7007D" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eoxh8-0004OM-GU for guix-devel@gnu.org; Thu, 22 Feb 2018 15:42:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eoxh3-0001ok-Jp for guix-devel@gnu.org; Thu, 22 Feb 2018 15:42:22 -0500 Received: from mail-out.m-online.net ([212.18.0.10]:43560) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eoxh3-0001nI-7c for guix-devel@gnu.org; Thu, 22 Feb 2018 15:42:17 -0500 In-Reply-To: <87371tqbyb.fsf@elephly.net> Content-Language: en-US List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Ricardo Wurmus Cc: guix-devel@gnu.org This is a multi-part message in MIME format. --------------D18AC0E3A759A08D0AF7007D Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, Am 22.02.2018 um 16:30 schrieb Ricardo Wurmus: >> re 2): As soon as Python2 and Python3 are installed in the same profil= e, >> we put both site-packages for both versions into PYTHONPATH, which >> obviously is wrong. >> >> $ PYTHONPATH=3D guix environment --ad-hoc python@2 python >> [=E2=80=A6] >> [guix] $ echo $PYTHONPATH >> /gnu/store/jkwp041kjy6li85n66ymxkfrr0hr2psj-profile/lib/python2.7/site= -packages:/gnu/store/jkwp041kjy6li85n66ymxkfrr0hr2psj-profile/lib/python3= .5/site-packages: >> >> A simple work-around would be to make the profile a (pseudo) virtual >> environment, which is a easy as creating a file >> "/gnu/store/=E2=80=A6-profile/pyvenv.cfg". This will trigger a mechani= sm in >> site.py to insert /gnu/store/=E2=80=A6-profile/lib/pythonX.Y/site-pack= ages" into >> sys.path - for the current python version only! > This is very good to know. I haven=E2=80=99t tested this (as I=E2=80=99= m not editing > the store by hand), but I suppose we could create an empty pyvenv.cfg i= n > a profile hook when Python packages are installed. Below please find a simple package which adds this hack. After installing it, unset PYTHONPATH: export PYTHONPATH=3D In the long run both python@2 and python@3 could propagate this hack-package, thus is would be installed whenever python is installed. (This need further investigation or a guix guru to help.) > (This wouldn=E2=80=99t help us much for wrapper scripts, though.) I have another hack in petto :) But one step at a time :-) Now here is the cat > guix-python-venv-hack.scm <<"EOF" ;;; Copyright =C2=A9 2018 Hartmut Goebel (use-modules (guix) (guix build-system trivial) (guix licenses)) (package (name "guix-python-venv-hack") (version "0.1") (source #f) (build-system trivial-build-system) (arguments `(#:modules ((guix build utils)) #:builder (begin (use-modules (guix build utils)) (let* ((out (assoc-ref %outputs "out")) (pyvenv.cfg (string-append out "/pyvenv.cfg"))) (mkdir-p out) (call-with-output-file pyvenv.cfg (lambda (p) (format p "#"))) ;;(chmod index.php #o555) )))) (synopsis "Python venc-hack for Guix") (description "See ...") (home-page #f) (license gpl3+)) EOF guix package --install-from-file guix-python-venv-hack.scm unset PYTHONPATH --=20 Regards Hartmut Goebel | Hartmut Goebel | h.goebel@crazy-compilers.com | | www.crazy-compilers.com | compilers which you thought are impossible | --------------D18AC0E3A759A08D0AF7007D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi,

Am 22.02.2018 um 16:30 schrieb Ricardo Wurmus:
re 2): As soon as Python2 and Python3 are installe=
d in the same profile,
we put both site-packages for both versions into PYTHONPATH, which
obviously is wrong.

$ PYTHONPATH=3D guix environment --ad-hoc python@2 python
[=E2=80=A6]
[guix] $ echo $PYTHONPATH
/gnu/store/jkwp041kjy6li85n66ymxkfrr0hr2psj-profile/lib/python2.7/site-pa=
ckages:/gnu/store/jkwp041kjy6li85n66ymxkfrr0hr2psj-profile/lib/python3.5/=
site-packages:

A simple work-around would be to make the profile a (pseudo) virtual
environment, which is a easy as creating a file
"/gnu/store=
/=E2=80=A6-profile/pyvenv.cfg". Th=
is will trigger a mechanism in
site.py to insert =
/gnu/store/=E2=80=A6-profil=
e/lib/pythonX.Y/site-packages" into
sys.path - for the current python version only!
This is very good to know.  I haven=E2=80=99t tested=
 this (as I=E2=80=99m not editing
the store by hand), but I suppose we could create an empty pyvenv.cfg in
a profile hook when Python packages are installed.

Below please find a simple package which adds this hack. After installing it, unset PYTHONPATH:
export PYTHONPATH=3D

In the long run both python@2 and python@3 could propagate this hack-package, thus is would be installed whenever python is installed. (This need further investigation or a guix guru to help.)<= br>
(This wouldn=E2=80=99t help us much for wrapper scri=
pts, though.)

I have another hack in petto :) But one step at a time :-)


Now here is the

cat > guix-python-venv-hack.scm <<"EOF"
;;; Copyright =C2=A9 2018 Hartmut Goebel <h.goebel@crazy-compil=
ers.com>

(use-modules (guix)
             (guix build-system trivial)
             (guix licenses))

(package
  (name "guix-python-venv-hack")
  (version "0.1")
  (source #f)
  (build-system trivial-build-system)
  (arguments
   `(#:modules ((guix build utils))
     #:builder
     (begin
       (use-modules (guix build utils))
       (let* ((out       (assoc-ref %outputs "out"))
              (pyvenv.cfg (string-append out "/pyvenv.cfg")))
         (mkdir-p out)
         (call-with-output-file pyvenv.cfg
           (lambda (p)
             (format p "#")))
         ;;(chmod index.php #o555)
         ))))
  (synopsis "Python venc-hack for Guix")
  (description "See ...")
  (home-page #f)
  (license gpl3+))
EOF
guix package --install-from-file guix-python-venv-hack.scm
unset PYTHONPATH
--=20
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@crazy-compilers.com   =
            |
| www.crazy-compilers.com | compilers which you thought are impo=
ssible |
--------------D18AC0E3A759A08D0AF7007D--