python模块的搜索路径如何理解?
python模块的搜索路径如何理解?
本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。
1、概念
加载模块的时候,系统会在哪些地方寻找此模块。
2、系统默认的模块搜索路径
importsys
sys.path属性可以获取路径列表
#案例p06.py
#案例p06.py
importsys
print(type(sys.path))
print(sys.path)
forpinsys.path:
print(p)
['D:\\python\\project\\包管理','D:\\PyCharmCommunityEdition2019.1.1\\helpers\\pydev','D:\\python\\project','D:\\PyCharmCommunityEdition2019.1.1\\helpers\\third_party\\thriftpy','D:\\PyCharmCommunityEdition2019.1.1\\helpers\\pydev','C:\\Users\\user\\.PyCharmCE2019.1\\system\\cythonExtensions','D:\\python\\project\\包管理','D:\\Anaconda3\\envs\\opp\\python37.zip','D:\\Anaconda3\\envs\\opp\\DLLs','D:\\Anaconda3\\envs\\opp\\lib','D:\\Anaconda3\\envs\\opp','D:\\Anaconda3\\envs\\opp\\lib\\site-packages']
D:\python\project\包管理
D:\PyCharmCommunityEdition2019.1.1\helpers\pydev
D:\python\project
D:\PyCharmCommunityEdition2019.1.1\helpers\third_party\thriftpy
D:\PyCharmCommunityEdition2019.1.1\helpers\pydev
C:\Users\user\.PyCharmCE2019.1\system\cythonExtensions
D:\python\project\包管理
D:\Anaconda3\envs\opp\python37.zip
D:\Anaconda3\envs\opp\DLLs
D:\Anaconda3\envs\opp\lib
D:\Anaconda3\envs\opp
D:\Anaconda3\envs\opp\lib\site-packages
3、添加搜索路径
sys.path.append(dir)
以上就是python模块的搜索路径介绍,希望能对大家有所帮助。更多Python学习教程请关注IT培训机构:千锋教育。

猜你喜欢LIKE
相关推荐HOT
更多>>
python里glob模块怎么用?
python里glob模块怎么用?本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。简单介绍:匹配一定的格式文件和文件夹。包含函数:1、glo...详情>>
2023-11-14 23:59:20
python中time.gmtime是什么
python中time.gmtime是什么下面我们就time.gmtime函数的概念、语法、参数、返回值、实例分别进行讲解。1.概念gmtime是把日期和时间转换为格林威...详情>>
2023-11-14 21:58:02
python使用OpenCV画图
python中使用OpenCV画图OpenCV的强大之处的一个体现就是其可以对图片进行任意编辑,处理。下面的这个函数最后一个参数指定的就是画笔的大小1、...详情>>
2023-11-14 19:49:08
python流式读取大文件的两种方法
python流式读取大文件的两种方法1、使用read方法分块读取使用更底层的file.read()方法,与直接循环迭代文件对象不同,每次调用file.read(chunk_...详情>>
2023-11-14 16:48:08热门推荐
python里glob模块怎么用?
沸python中series转dataframe的两种方法
热python实现矩阵乘法运算的几种方法
热pandas遍历dataframe的方法有哪些
新python中time.gmtime是什么
python中RNN和LSTM的基本介绍
Python中for循环进行字典迭代
Python中哈希结构有哪几种?
python使用OpenCV画图
python绝对和相对导入的介绍
python标识符是什么意思?
python中如何查看stdin编码?
python如何访问列表元素?
python如何提取文本信息?
技术干货






