solution for python can not import local module
这次遇到的问题是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
PYTHONPATHexists, 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}\PythonPathunder both theHKEY_CURRENT_USERandHKEY_LOCAL_MACHINEhives. Subkeys which have semicolon-delimited path strings as their default value will cause each path to be added tosys.path. (Note that all known installers only use HKLM, so HKCU is typically empty.) - If the environment variable
PYTHONHOMEis set, it is assumed as “Python Home”. Otherwise, the path of the main Python executable is used to locate a “landmark file” (eitherLib\os.pyorpythonXY.zip) to deduce the “Python Home”. If a Python home is found, the relevant sub-directories added tosys.path(Lib,plat-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
PYTHONPATHis 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的更多相关文章
- 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 ...
- 在eclipse中用java调用python报错 Exception in thread "main" ImportError: Cannot import site module and its dependencies
最近做项目需要用java调用python,配置了jython后,运行了例子代码: 获得一个元组里面的元素: import org.python.util.PythonInterpreter; publ ...
- python 之禅 import this
dongweiming的博客 前言 我这个博客一直都是一些技术分享,show code的地方,我从来没有写过个人生活或者情感杂谈,当然我也从来没有谈论过我对什么东西的喜恶. 很多人喜欢喷XX语言,喜欢 ...
- Python中的import语句
Python中的import语句是导入一个文件,这条语句主要做三件事: 1 通过一定的方式,搜寻要导入的文件: 2 如果需要,就编译这个文件: 3 运行这个文件 但是,需要注意的是,所有这三个步骤,都 ...
- python tips(3);import的机制
1.标准的import python中,所有加载到内存中的模块都是放在sys.modules中,当import一个模块的时候,会在这个列表中查看是否加载了这个模块,如果加载了,则只是将模块名字加入到正 ...
- 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 ...
- python 小技巧(import模块、查询类继承关系、安装包)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在这里列举一些我使用Python时积累的小技巧.这些技巧是我在使用Python过程 ...
- python 导入模块 import 理解
--python 导入模块 import 理解 -----------------------------------2014/03/18 python 导入一个模块的过程要求有一个叫做“路径搜索”的 ...
- python中的import,reload,以及__import__
python中的import,reload,以及__import__ 分类: UNIX/LINUX C/C++LINUX/UNIX shellpython2013-04-24 20:294536人阅读 ...
随机推荐
- codeforces-1132 (div2)
A.发现b的个数没有意义,a不等于d一定不可行,c不管多少都算一个,如果只有c没有ad也不可行 #include <map> #include <set> #include & ...
- Dynamics CRM - 使用 C# Plugin 调用 SQL 存储过程
有时候,在 Dynamics CRM Plugin 中通过 linq 查询数据会比较慢,可以通过采用在 C# plugin 中直接调用数据库存储过程的方式来提高效率,具体过程如下: 1.新建一个存储过 ...
- vue md5
安装 cnpm install js-md5 --save 使用 import md5 from 'js-md5' md5('要加密的内容')
- 初次接触scrapy框架
初次接触这个框架,先订个小目标,抓取QQ首页,然后存入记事本. 安装框架(http://scrapy-chs.readthedocs.io/zh_CN/0.24/intro/install.html) ...
- CORS跨域 Ajax headers 问题
今天我们遇到了一个CORS跨域的问题Ajax如下 var url = "http://localhost:11980/api/Demo/GetString"; //api地址 $. ...
- ultraEdit软件比较两个文件内容的不同处
1.软件名称为:UltraEdit ,安装并打开软件; 软件图标: 打开软件如图所示: 2.点击导航图标,蓝色上面有Uc图标,该图标名称为“比较文件” 如图位置: 3.弹出框,根据文件路径选择好比较的 ...
- SVN clean失败解决方法
一.问题描述 1.svn 更新或者提交时,报错:svn cleanup failed–previous operation has not finished; run cleanup if it wa ...
- python捕获异常及方法总结
调试Python程序时,经常会报出一些异常,异常的原因一方面可能是写程序时由于疏忽或者考虑不全造成了错误,这时就需要根据异常Traceback到出错点,进行分析改正:另一方面,有些异常是不可避免的,但 ...
- CNN的反向传播
在一般的全联接神经网络中,我们通过反向传播算法计算参数的导数.BP 算法本质上可以认为是链式法则在矩阵求导上的运用.但 CNN 中的卷积操作则不再是全联接的形式,因此 CNN 的 BP 算法需要在原始 ...
- 秋名山老司机(BS4与正则的比拼)
因为嘉伟思杯里的一个脚本题目,16进制计算,python3正则还没学,所以没写出来.大佬跟我说也可以用BS4,从DOM上下手,直接爬下来直接一个eval就搞定了,eval可以像这样计算16进制,eva ...