2012-04-26 3 views
2

내 PYTHONPATH를 정리하고 싶습니다.python on linux : PYTHONPATH를 설정할 수있는 모든 곳은 무엇입니까?

내가 알고있는 나는, /home/me/.profile에 그것을 추가 그래서 같은 :

PYTHONPATH=/home/hoff/code/someproject/pythonmods:$PYTHONPATH 
PYTHONPATH=/home/hoff/code/google_appengine/google/appengine/tools:$PYTHONPATH 
export PYTHONPATH 

하지만 파이썬 인터프리터로 가서 봐 때 나는 PYTHONPATH를 추가 한 다른 장소가 있어야합니다 sys.path에는 모든 종류의 추가 디렉토리가 있습니다.

어디에 지정했는지, 즉 PYTHONPATH (Linux/우분투에서)를 추가 할 수있는 모든 장소는 무엇입니까?

답변

1

이전과 마찬가지로 ... 거의 모든 곳에서 설정할 수 있습니다. 내가 볼 것 몇 곳 (로그인 쉘은 전형적인 배쉬 가정하고 ...) man bash

When bash is invoked as an interactive login shell, or as 
    a non-interactive shell with the --login option, it first 
    reads and executes commands from the file /etc/profile, 
    if that file exists. After reading that file, it looks for 
    ~/.bash_profile, ~/.bash_login, and ~/.profile 

에서

.bashrc 
/etc/profile 
Anything in /etc/profile.d/ (typically loaded from /etc/profile) 
~/.bash_profile 
~/.bash_login 

When an interactive shell that is not a login shell is started, 
    bash reads and executes commands from ~/.bashrc, if that 
    file exists. 
+0

.bashrc에 내가 장소였다 찾고, 거기에 "내보내기 pythonpath"무리가 ... – Hoff

3

sys.pathPYTHONPATH은 같은 것이 아닙니다. 전자는 후자를 포함한다. PYTHONPATH 값을 찾으려면 셸에서 echo $PYTHONPATH을 실행하십시오.

파일은 /usr/{local/,}lib/pythonX.Y/dist-packages/site.pysys.path 그래서 당신이 apt-get, easy_installpip 설치 패키지를 가져올 수 있습니다 업데이트합니다. 이 패키지를 제거하면 sys.path (비록 PYTHONPATH이 아님)이 정리됩니다.

1

어디서나 환경 변수를 설정할 수 있습니다.

프로세스는 부모 환경을 상속하므로 쉘 구성 파일, 쉘 명령 행, 사용자가 호출하는 중개 스크립트, Python 스크립트 (sys.path 포함) 또는 라이브러리 it의 모든 단계에서 프로세스를 수정할 수 있습니다 용도.