Python 2.7: sys.path vs. PYTHONPATH

Hallo, ich habe gerade ein eigenartiges Problem nach dem Übergang von Python 2.6 auf 2.7. Einige Pakete werden bei mir lokal installiert, z.B. pyfits, mittels setuptools $ export PYTHONPATH=/mylocal/python/lib64/python2.7/site-packages/ $ python setup.py install --prefix=/mylocal/python $ ls -l $PATHONPATH drwxr-xr-x 4 oles ata 4096 Sep 16 09:52 distribute-0.6.19-py2.7.egg -rw-r--r-- 1 oles ata 286 Sep 16 10:16 easy-install.pth drwxr-xr-x 4 oles ata 34 Sep 16 09:52 pyfits-3.0-py2.7-linux-x86_64.egg -rw-r--r-- 1 oles ata 30 Sep 16 09:52 setuptools.pth -rw-r--r-- 1 oles ata 2362 Sep 16 09:52 site.py -rw-r--r-- 1 oles ata 1757 Sep 16 09:52 site.pyc $ Den Pfad möchte ich jetzt in einem Script verwenden: -----------8<----------------- #!/usr/bin/env python import sys sys.path.append('/mylocal/python/lib64/python2.7/site-packages/') import pyfits print pyfits.__version__ -----------8<----------------- $ unset PYTHONPATH $ python test.py Traceback (most recent call last): File "test.py", line 4, in <module> import pyfits ImportError: No module named pyfits $ Unter 2.6 hatte das noch so funktioniert. Was hat sich da verändert? Viele Grüße Ole

Am 16.09.2011 10:26, schrieb Ole Streicher:
Unter 2.6 hatte das noch so funktioniert. Was hat sich da verändert?
Sicher, dass das unter 2.6 funktioniert hat? Die .pth-Files werden beim Starten von Python vom Modul `site` abgearbeitet. Also muss das Verzeichnis in PYTHONPATH sein, wenn Du dort .pth-Dateien verwenden möchtest. M.E. ergibt die Installationsmethode, die Du verwendest, so keinen Sinn. Denn offensichtlich willst Du "site-packages" um Deinen Pfad erweitern. Dann mach es aber doch richtig und setzte PYTHONPATH. Oder verwende virtualenv. -- Schönen Gruß - Regards Hartmut Goebel Dipl.-Informatiker (univ.), CISSP, CSSLP Goebel Consult Spezialist für IT-Sicherheit in komplexen Umgebungen http://www.goebel-consult.de Monatliche Kolumne: http://www.cissp-gefluester.de/ Goebel Consult ist Mitglied bei http://www.7-it.de
participants (2)
-
Hartmut Goebel
-
Ole Streicher