2009-09-19 6 views
2

J'utilise Mac OS X 10.5.8. J'ai installé Python 2.6 sur le site. C'est dans mon répertoire d'application. J'ai modifié mon .bash_profile avoir:IDLE et Python ont des chemins différents sous Mac OS X

# Setting PATH for MacPython 2.6 
# The orginal version is saved in .bash_profile.pysave 
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" 
export PATH 
export PATH=/usr/local/mysql/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin 
export PYTHONPATH=/Users/blwatson/pythonpath:/Users/blwatson/pythonpath/django/bin:$PYTHONPATH 

quand je lance python à partir de l'invite de commande, je peux obtenir ce qui suit:

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import django 
>>> django.VERSION 
(1, 0, 4, 'alpha', 0) 

vérification PATH

>>> import sys 
>>> sys.path 
['', '/Users/blwatson/pythonpath', '/Users/blwatson/pythonpath/django/bin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wx-2.8-mac-unicode'] 
>>> 

Quand je suis dans IDLE, j'obtiens une expérience différente.

Python 2.6.2 (r262:71600, Apr 16 2009, 09:17:39) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin 
Type "copyright", "credits" or "license()" for more information. 

    **************************************************************** 
    Personal firewall software may warn about the connection IDLE 
    makes to its subprocess using this computer's internal loopback 
    interface. This connection is not visible on any external 
    interface and no data is sent to or received from the Internet. 
    **************************************************************** 

IDLE 2.6.2  
>>> import django 

Traceback (most recent call last): 
    File "<pyshell#0>", line 1, in <module> 
    import django 
ImportError: No module named django 
>>> import sys 
>>> print sys.path 
['/Users/blwatson/Documents', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/PIL', '/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wx-2.8-mac-unicode'] 

Je n'ai aucune idée de ce qui se passe. Je suis passé d'un ordinateur portable à l'autre et j'ai fait tout le truc TimeCapsule, donc je sais qu'il y a un conflit à cause de ça. Où est IDLE obtenir le chemin? Pourquoi ne puis-je pas importer Django?

+0

Non seulement cela, mais vous remarquerez que BBEdit et Komodo Edit auront des problèmes similaires. –

Répondre

2

Comme tous les ensembles d'applications OS X, si vous lancez IDLE.app en double-cliquant, un shell n'est pas impliqué et donc. bash_profile ou d'autres fichiers d'initialisation de shell ne sont pas appelés. Il existe un moyen de définir les variables d'environnement de session utilisateur à l'aide d'un property list file (~/.MacOSX/environment.plist) spécial mais c'est vraiment un peu un kludge et non recommandé. Heureusement, il existe une solution plus simple: sur OS X, il est également possible d'invoquer IDLE à partir d'une ligne de commande shell dans une fenêtre de terminal. De cette façon, il héritera des variables d'environnement exportées de ce shell comme vous pouvez vous y attendre. Donc, quelque chose comme:

$ export PYTHONPATH= ... 
$ /usr/local/bin/idle2.6 

Il y avait plusieurs incohérences et des problèmes avec IDLE sur OS X avant 2.6.2 en fonction de la façon dont il a été invoqué Je recommande donc en utilisant rien de plus que la python.org 2.6.2 ou 3.1 versions sur OS X.

EDIT: Je vois à partir de la page de manuel open(1) que, depuis 10.4, les applications lancées via open héritent également des variables d'environnement qui fonctionneraient aussi à partir de la ligne de commande. Si vous voulez éviter d'ouvrir une fenêtre de terminal, il est facile de créer une application de lancement simple en utilisant AppleScript ou Automator (ou même Python avec py2app!). Dans ce cas, utilisez la commande de commande ouverte afin que l'application de lancement ne reste pas assise. Par exemple, dans Automator, choisissez l'action Run Shell Script et d'ajouter:

export PYTHONPATH= ... 
open -a "/Applications/Python 2.6/IDLE.app" 

Enregistrer comme format de fichier Application (en 10.5) et vous devriez avoir un moyen cliquable pour lancer un IDLE sur mesure.

+0

Exécution à partir de la ligne de commande a travaillé. C'est embêtant que je dois lancer le terminal, mais cela fera ... merci beaucoup !! –

Questions connexes