如何设置python模块的默认搜索路径?

Python025

如何设置python模块的默认搜索路径?,第1张

Python的模块搜索路径PYTHONPATH类似Java的CLASSPATH\x0d\x0a由以下路径组合而成,通过更改以下4者其中之一都可以改变Python模块的默认搜索路径:\x0d\x0a1.当前工作目录\x0d\x0a2.操作系统的PYTHONPATH环境变量\x0d\x0a3.Python安装目录lib/site-packages中或PYTHONPATH中的.pth文件定义的路径\x0d\x0a如:find~/my_lib-typed-print>~/python2.6/site-packages/my_lib.pth\x0d\x0a4.运行时对sys.path的改变,如:\x0d\x0a\x0d\x0a向后增加:\x0d\x0asys.path.append(path)\x0d\x0apath不要以/或\结尾。\x0d\x0a向前增加:\x0d\x0asys.path.insert(0,path)

pycharm设置python路径步骤如下:

点击File-》settings,弹出设置对话框

点击Project-》Project Interpreter,在右侧Project Interpreter下拉,选择python路径,实现pycharm的python路径设置。本次设置为minicoda安装的python3。

如下图所示