>>> pprint.pprint(sys.path)
['',
'/home/xx/$PYTHONPATH',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
注意:将自己的包/模块 放入到这些个目录中,即可用。
>>> import flash
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'flash'
>>> sys.path.append('/home/xx/Codes/eclipse/pythonbook/xx/')
>>> pprint.pprint(sys.path)
['',
'/home/xx/$PYTHONPATH',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/xx/Codes/eclipse/pythonbook/xx/']
>>> import flash
>>> flash.flashprint('beauty')
Flash Print: beauty
sudo gedit /etc/environment # Terminal 打开环境变量文件
export PYTHONPATH=$PYTHONPATH:/home/xx/Codes/eclipse/pythonbook/xx/ # 文件中增加PYTHONPATH值
source /etc/environment # Terminal 中使之生效
效果是:
>>> pprint.pprint(sys.path)
['',
'/home/xx/$PYTHONPATH',
'/home/xx/Codes/eclipse/pythonbook/xx',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
>>> flash.flashprint('beauty')
Flash Print: beauty
├── pythonbook
│ ├── xx
│ │ ├── flash.py
│ └── yy
│ ├── conf.pth
│ └── test.py
conf.pth 内容
/home/xx/Codes/eclipse/pythonbook/xx/
test.py 内容
print('YY is outputting')
import flash
flash.flashprint('beauty')
>>> pprint.pprint(sys.path)
['',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']