blog

这次遇到的问题是sys.path的输出不包含'',导致无法import当前文件和文件夹

When no ._pth file is found, this is how sys.path is populated on Windows:

  • An empty entry is added at the start, which corresponds to the current directory.
  • If the environment variable PYTHONPATH exists, as described in Environment variables, its entries are added next. Note that on Windows, paths in this variable must be separated by semicolons, to distinguish them from the colon used in drive identifiers (C:\ etc.).
  • Additional “application paths” can be added in the registry as subkeys of\SOFTWARE\Python\PythonCore{version}\PythonPath under both the HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE hives. Subkeys which have semicolon-delimited path strings as their default value will cause each path to be added to sys.path. (Note that all known installers only use HKLM, so HKCU is typically empty.)
  • If the environment variable PYTHONHOME is set, it is assumed as “Python Home”. Otherwise, the path of the main Python executable is used to locate a “landmark file” (either Lib\os.py or pythonXY.zip) to deduce the “Python Home”. If a Python home is found, the relevant sub-directories added to sys.path (Libplat-win, etc) are based on that folder. Otherwise, the core Python path is constructed from the PythonPath stored in the registry.
  • If the Python Home cannot be located, no PYTHONPATH is specified in the environment, and no registry entries can be found, a default path with relative entries is used (e.g. .\Lib;.\plat-win, etc).

解决方案删除._pth文件,解决这个bug的经验教训就是一定要一步一步跟踪到问题原因,论英文文档的重要性

solution for python can not import local module的更多相关文章

  1. virtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper.........(解决办法)

    Linux(ubuntu)上python2与python3共存环境下,安装virtualenvwrapper后, 其环境变量被自动设置为VIRTUALENVWRAPPER_PYTHON=/usr/bi ...

  2. 在eclipse中用java调用python报错 Exception in thread "main" ImportError: Cannot import site module and its dependencies

    最近做项目需要用java调用python,配置了jython后,运行了例子代码: 获得一个元组里面的元素: import org.python.util.PythonInterpreter; publ ...

  3. python 之禅 import this

    dongweiming的博客 前言 我这个博客一直都是一些技术分享,show code的地方,我从来没有写过个人生活或者情感杂谈,当然我也从来没有谈论过我对什么东西的喜恶. 很多人喜欢喷XX语言,喜欢 ...

  4. Python中的import语句

    Python中的import语句是导入一个文件,这条语句主要做三件事: 1 通过一定的方式,搜寻要导入的文件: 2 如果需要,就编译这个文件: 3 运行这个文件 但是,需要注意的是,所有这三个步骤,都 ...

  5. python tips(3);import的机制

    1.标准的import python中,所有加载到内存中的模块都是放在sys.modules中,当import一个模块的时候,会在这个列表中查看是否加载了这个模块,如果加载了,则只是将模块名字加入到正 ...

  6. python 的 from import 机制

    [A.py] from B import D class C:pass [B.py] from A import C class D:pass 为什么执行A的时候不能加载D呢? 如果将A.py改为:i ...

  7. python 小技巧(import模块、查询类继承关系、安装包)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在这里列举一些我使用Python时积累的小技巧.这些技巧是我在使用Python过程 ...

  8. python 导入模块 import 理解

    --python 导入模块 import 理解 -----------------------------------2014/03/18 python 导入一个模块的过程要求有一个叫做“路径搜索”的 ...

  9. python中的import,reload,以及__import__

    python中的import,reload,以及__import__ 分类: UNIX/LINUX C/C++LINUX/UNIX shellpython2013-04-24 20:294536人阅读 ...

随机推荐

  1. 集合源码分析[3]-ArrayList 源码分析

    历史文章: Collection 源码分析 AbstractList 源码分析 介绍 ArrayList是一个数组队列,相当于动态数组,与Java的数组对比,他的容量可以动态改变. 继承关系 Arra ...

  2. min-max容斥

    这玩意儿一般都是跟概率期望结合的吧,就是下面这个式子(\(max(S)\)代表集合\(S\)中的最大值,\(min(S)\)同理): \[max(S)=\sum\limits_{T\subseteq ...

  3. 随机逻辑回归random logistic regression-特征筛选

    python信用评分卡(附代码,博主录制) https://study.163.com/course/introduction.htm?courseId=1005214003&utm_camp ...

  4. 强连通分量(Tarjan)

    //P2002解题思路: //先求SCC,缩点后,转换为DAG(有向无环图) //在DAG上统计入度为0的scc数量即可 //Tarjan时间复杂度:O(N+E),每个点和每条边刚好被访问一次,在空间 ...

  5. 多项式求导系列——OO Unit1分析和总结

    一.摘要 本文是BUAA OO课程Unit1在课程讲授.三次作业完成.自测和互测时发现的问题,以及倾听别人的思路分享所引起个人的一些思考的总结性博客.本文第二部分介绍三次作业的设计思路,主要以类图的形 ...

  6. 使用hql动态创建对象问题

    前段时间由于需求要添加报表数据,调整ireport后,打印pdf文件出现数据错位的情况,调试发现不是ireport问题,就查看了后台传送的数据,最后发现传送的对象属性值已经就是错位的,那就是获取对象时 ...

  7. Microsoft Internet Explorer v11 / XML External EntityInjection 0day

    [+] Credits: John Page (aka hyp3rlinx) [+] Website: hyp3rlinx.altervista.org[+] Source:  http://hyp3 ...

  8. 同一台电脑同时装jdk1.8和jdk1.7

    因为之前安装的eclipse版本要求JDK1.8或以上的版本,但在搭建SSH框架的时候老是报错,又找不到2错误源.老师建议换个低版本的jdk.所以jdk版本需要降级. 但降级以后就不能打开eclips ...

  9. 执行docker命令遇到 Get Permission Denied

    安装完docker后,执行docker相关命令,出现: Got permission denied while trying to connect to the Docker daemon socke ...

  10. 软件测试-培训的套路-log3

    最新的套路!我是没了解过--下图中描述-log3 Dotest-董浩 但是我知道不管什么没有白吃的午餐而且还会给钱…如果真的有,请醒醒! 当然话又回来,套路不套路,关键看你是否需要:你如果需要我觉得是 ...