python模块的搜索路径概念
python加载模块的时候,系统会在哪些地方寻找此模块。
系统默认的模块搜索路径
import sys sys.path 属性可以获取路径列表 # 案例 p06.py
# 案例 p06.py import sys print(type(sys.path)) print(sys.path) for p in sys.path: print(p)<class 'list'> ['D:\\python\\project\\包管理', 'D:\\PyCharm Community Edition 2019.1.1\\helpers\\pydev', 'D:\\python\\project', 'D:\\PyCharm Community Edition 2019.1.1\\helpers\\third_party\\thriftpy', 'D:\\PyCharm Community Edition 2019.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:\PyCharm Community Edition 2019.1.1\helpers\pydev D:\python\project D:\PyCharm Community Edition 2019.1.1\helpers\third_party\thriftpy D:\PyCharm Community Edition 2019.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模块的搜索路径介绍,希望能对大家有所帮助。
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试