python中import一个模块时python解释器的搜索目录顺序:
参考python帮助文档
The Module Search Path
When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variablesys.path. sys.path is initialized from these locations:
After initialization, Python programs can modify sys.path. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section Standard Modules for more information.
这里也有一篇: Understanding imports and PYTHONPATH
环境变量
PATH是告诉操作系统到哪些目录里找可执行文件
PYTHONPATH是告诉python解释器到哪些目录去找要加载的模块
Windows找DLL的顺序
With both implicit and explicit linking, Windows first searches for "known DLLs", such as Kernel32.dll and User32.dll. Windows then searches for the DLLs in the following sequence:
The directory where the executable module for the current process is located.
参考:msdn
原文地址:http://www.cnblogs.com/wxz888/p/3767370.html