当前位置: 首页 > 图灵资讯 > 行业资讯> python模块的搜索路径如何理解?

python模块的搜索路径如何理解?

来源:图灵python
时间: 2024-08-27 13:58:14

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

1、概念

在加载模块时,系统将在哪里找到该模块。

2、该系统默认模块搜索路径

importsys
sys.可以获得路径列表的path属性
#案例p06.py
#案例p06.py
importsys

print(type(sys.path))
print(sys.path)

forpinsys.path:
print(p)
<class'list'>
['D:\\python\\project\包管理','D:\PyCharmmunityedition.1\\helpers\\pydev','D:\\python\\project','D:\PyCharmmunityedition.1\\helpers\\third_party\\thriftpy','D:\PyCharmmunityedition.1\\helpers\\pydev','C:\\Users\\user\\.Pycharmce2019.1system\\cythonExtensions','D:\\python\\project\包管理','D:\anaconda3envs\\opp\python377.zip','D:\anaconda3envs\\opp\\DLLs','D:\anaconda3envs\\opp\\lib','D:\anaconda3envs\\opp','D:\anaconda3envs\\opp\\lib\\site-packages']
D:\python\project\包管理
D:2019.19.PyCharmCommunityEdition.1\helpers\pydev
D:\python\project
D:2019.19.PyCharmCommunityEdition.1\helpers\third_party\thriftpy
D:2019.19.PyCharmCommunityEdition.1\helpers\pydev
C:\Users\user\.2019年Pycharmcesystem\cythonExtensions
D:\python\project\包管理
D:Anaconda3envs\opp\python37.zip
D:Anaconda3envs\opp\DLLs
D:Anaconda3envs\opp\lib
D:Anaconda3envs\opp
D:Anaconda3envs\opp\lib\site-packages

3、添加搜索路径

sys.path.append(dir)

以上是python模块搜索路径的介绍,希望能对大家有所帮助。更多Python学习指导:python基础教程