python:sys.path

sys.path

[root@fedora bin]# python
Python 2.4.3 (#1, Nov 19 2007, 02:42:21)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for p in sys.path:
...     print p
...

/usr/local/lib/python24.zip
/usr/local/lib/python2.4
/usr/local/lib/python2.4/plat-linux2
/usr/local/lib/python2.4/lib-tk
/usr/local/lib/python2.4/lib-dynload
/usr/local/lib/python2.4/site-packages
 
[root@fedora bin]# python2.5
Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for p in sys.path:
...    print p
...

/usr/lib/python2.5/site-packages/python_twitter-0.5-py2.5.egg
/usr/lib/python25.zip
/usr/lib/python2.5
/usr/lib/python2.5/plat-linux2
/usr/lib/python2.5/lib-tk
/usr/lib/python2.5/lib-dynload
/usr/lib/python2.5/site-packages
/usr/lib/python2.5/site-packages/gtk-2.0
 

PYTHONPATH

[root@fedora python2.5]# PYTHONPATH=~ python2.5
Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for p in sys.path:
...    print p
...

/usr/lib/python2.5/site-packages/python_twitter-0.5-py2.5.egg
/root
/usr/lib/python25.zip
/usr/lib/python2.5
/usr/lib/python2.5/plat-linux2
/usr/lib/python2.5/lib-tk
/usr/lib/python2.5/lib-dynload
/usr/lib/python2.5/site-packages
/usr/lib/python2.5/site-packages/gtk-2.0
 

*.pth

[admin@fedora ~]$ cat /usr/lib/python2.5/site-packages/easy-install.pth
import sys; sys.__plen = len(sys.path)
./python_twitter-0.5-py2.5.egg
import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,
'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)
[root@fedora ~]# echo "/home/hide" >> /usr/lib/python2.5/site-packages/easy-install.pth


[root@fedora ~]# python2.5
Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for p in sys.path:
...    print p
...

/usr/lib/python2.5/site-packages/python_twitter-0.5-py2.5.egg
/usr/lib/python25.zip
/usr/lib/python2.5
/usr/lib/python2.5/plat-linux2
/usr/lib/python2.5/lib-tk
/usr/lib/python2.5/lib-dynload
/usr/lib/python2.5/site-packages
/home/hide
/usr/lib/python2.5/site-packages/gtk-2.0

[root@fedora python2.5]# cat ./site-packages/pygtk.pth
gtk-2.0

*.pth のファイル名順でソートされて追加されるんでしょう。

so

./config/のsoも追加?

[root@fedora config]# grep plat-linux2 *
Binary file libpython2.5.a matches
Binary file libpython2.5.so matches
[root@fedora config]# grep lib-tk *
Makefile:TKPATH=:lib-tk
Makefile:LIBSUBDIRS=    lib-tk site-packages test test/output test/data \
Setup:TKPATH=:lib-tk
Binary file libpython2.5.a matches
Binary file libpython2.5.so matches
[root@fedora config]# grep dynload *
Makefile:DESTSHARED=    $(BINLIBDEST)/lib-dynload
Makefile:DYNLOADFILE=   dynload_shlib.o
Binary file libpython2.5.a matches
Binary file libpython2.5.so matches

 

PYTHONHOME

[root@fedora config]# export PYTHONHOME=/tmp
[root@fedora config]# python2.5
'import site' failed; use -v for traceback
Python 2.5 (r25:51908, Nov  6 2007, 16:54:01)
[GCC 4.1.2 20070925 (Red Hat 4.1.2-27)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> for p in sys.path:
...    print p
...

/tmp/lib/python25.zip
/tmp/lib/python2.5/
/tmp/lib/python2.5/plat-linux2
/tmp/lib/python2.5/lib-tk
/tmp/lib/python2.5/lib-dynload
 
/tmp以下にはsite-packagesとかないので今回は評価されない。pthとかも。
 

site.py

python起動時に呼ばれる。パス関係もここで設定される。
[root@fedora ~]# pydoc site
Help on module site:

NAME
    site - Append module search paths for third-party packages to sys.path.

FILE
    /usr/local/lib/python2.4/site.py

MODULE DOCS
    http://www.python.org/doc/current/lib/module-site.html

DESCRIPTION
    ****************************************************************
    * This module is automatically imported during initialization. *
    ****************************************************************

決まりごと

  • $PYTHONHOME/lib/python25.zip
  • $PYTHONHOME/lib/python2.5/

は固定?

 

sys.path

[admin@fedora ~]$ pydoc sys.path

Help on list in sys object:

sys.path = class list(object)
|  list() -> new list
|  list(sequence) -> new list initialized from sequence’s items
|
|  Methods defined here:
|
|  __add__(…)
|      x.__add__(y) <==> x+y
|
|  __contains__(…)
|      x.__contains__(y) <==> y in x
|
|  __delitem__(…)
|      x.__delitem__(y) <==> del x[y]
|
|  __delslice__(…)
|      x.__delslice__(i, j) <==> del x[i:j]
|
|      Use of negative indices is not supported.
|
|  __eq__(…)
|      x.__eq__(y) <==> x==y
|
|  __ge__(…)
|      x.__ge__(y) <==> x>=y
|
|  __getattribute__(…)
|      x.__getattribute__(‘name’) <==> x.name
|
|  __getitem__(…)
|      x.__getitem__(y) <==> x[y]
|
|  __getslice__(…)
|      x.__getslice__(i, j) <==> x[i:j]
|
|      Use of negative indices is not supported.
|
|  __gt__(…)
|      x.__gt__(y) <==> x>y
|
|  __hash__(…)
|      x.__hash__() <==> hash(x)
|
|  __iadd__(…)
|      x.__iadd__(y) <==> x+=y
|
|  __imul__(…)
|      x.__imul__(y) <==> x*=y
|
|  __init__(…)
|      x.__init__(…) initializes x; see x.__class__.__doc__ for signature
|
|  __iter__(…)
|      x.__iter__() <==> iter(x)
|
|  __le__(…)
|      x.__le__(y) <==> x<=y
|
|  __len__(…)
|      x.__len__() <==> len(x)
|
|  __lt__(…)
|      x.__lt__(y) <==> x<y
|
|  __mul__(…)
|      x.__mul__(n) <==> x*n
|
|  __ne__(…)
|      x.__ne__(y) <==> x!=y
|
|  __repr__(…)
|      x.__repr__() <==> repr(x)
|
|  __reversed__(…)
|      L.__reversed__() — return a reverse iterator over the list
|
|  __rmul__(…)
|      x.__rmul__(n) <==> n*x
|
|  __setitem__(…)
|      x.__setitem__(i, y) <==> x[i]=y
|
|  __setslice__(…)
|      x.__setslice__(i, j, y) <==> x[i:j]=y
|
|      Use  of negative indices is not supported.
|
|  append(…)
|      L.append(object) — append object to end
|
|  count(…)
|      L.count(value) -> integer — return number of occurrences of value
|
|  extend(…)
|      L.extend(iterable) — extend list by appending elements from the iterable
|
|  index(…)
|      L.index(value, [start, [stop]]) -> integer — return first index of value
|
|  insert(…)
|      L.insert(index, object) — insert object before index
|
|  pop(…)
|      L.pop([index]) -> item — remove and return item at index (default last)
|
|  remove(…)
|      L.remove(value) — remove first occurrence of value
|
|  reverse(…)
|      L.reverse() — reverse *IN PLACE*
|
|  sort(…)
|      L.sort(cmp=None, key=None, reverse=False) — stable sort *IN PLACE*;
|      cmp(x, y) -> -1, 0, 1
|
|  ———————————————————————-
|  Data and other attributes defined here:
|
|  __new__ = <built-in method __new__ of type object>
|      T.__new__(S, …) -> a new object with type S, a subtype of T

 
カテゴリー: 未分類 パーマリンク

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中