Python 模組儲存在哪裡?


Python 模組通常儲存在 Python 資料夾中的 /lib/site-packages 中。如果你想了解匯入模組時 Python 會檢查哪些目錄,可以記錄以下內容

>>> import sys
>>> print sys.path
['', 'C:\Python27', 'C:\Python27\Lib\site-packages', 'C:\Python27\Lib', 'C:\Python27\DLLs', 'C:\Python27\Lib\lib-tk', 'C:\Python27\Scripts', 'C:\WINDOWS\SYSTEM32\python27.zip', 'C:\Python27\lib\plat-win', 'C:\Python27\lib\site-packages\win32', 'C:\Python27\lib\site-packages\win32\lib', 'C:\Python27\lib\site-packages\Pythonwin']

你還可以使用 python -v 命令來列出指令碼(比如 hello.py)正在使用的各個模組在系統中儲存的位置。例如,

$ python -v hello.py
PS C:\Users\Ayush> echo 'import scrapy' > hello.py
PS C:\Users\Ayush> python -v hello.py
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# C:\Python27\Lib\site.pyc matches C:\Python27\Lib\site.py
import site # precompiled from C:\Python27\Lib\site.pyc
# C:\Python27\Lib\os.pyc matches C:\Python27\Lib\os.py
...
...

更新時間: 2019-10-01

3千次+瀏覽

開啟你的職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.