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.