我面临一个非常奇怪的问题.我有三个文件,第一个包含基类,其他两个文件中的类继承自该基类.
奇怪的是,昨天一切正常,但其中一个文件今天不再起作用了.在此期间我没有触及过进口商品.
.
└── orangecontrib
├──__init__.py
└── prototypes
├──__init__.py
└── widgets
├──__init__.py
├── owpythagorastree.py
├── owclassificationpythagorastree.py
└── owregressionpythagorastree.py
因此,分类和回归类需要从基类继承,并且导入以完全相同的方式完成:
owclassificationpythagorastree.py
...
from orangecontrib.prototypes.widgets.owpythagorastree import OWPythagorasTree
...
owregressionpythagorastree.py
...
from orangecontrib.prototypes.widgets.owpythagorastree import OWPythagorasTree
...
然而,当我尝试从命令行运行这两个脚本(使用python owregressionpythagorastree.py)时,回归小部件工作正常,但分类小部件会产生以下错误:
Traceback (most recent call last): File
“owclassificationpythagorastree.py”,line 6,in
from orangecontrib.prototypes.widgets.owpythagorastree import OWPythagorasTree ImportError: No module named
‘orangecontrib.prototypes’
这种情况在其他项目中也曾多次发生,但它最终会自行解决.但令我困扰的是,我不知道造成这种情况的原因.
我尝试从我的常规机器和python virtualenv运行这个,我安装了模块(我在基本目录中使用pip install -e.).
我没有看到这种行为的明显原因,这让我很烦恼,所以任何帮助或洞察为什么会发生这种情况以及如何解决这一问题将不胜感激.
编辑
根据要求,我运行了import sys; print(sys.path)位于两个脚本的顶部,在通过diff运行后,它们都完全相同.不过,我在这里发布结果.
[‘/home/pavlin/dev/orange3-prototypes/orangecontrib/prototypes/widgets’,
‘/home/pavlin/dev/orange3’,
‘/home/pavlin/dev/orange3env/lib/python3.5/site-packages/setuptools_git-1.1-py3.5.egg’,
‘/home/pavlin/dev/orange-bio’,
‘/home/pavlin/dev/orange3env/lib/python3.5/site-packages/pyqtgraph-0.9.10-py3.5.egg’,
‘/home/pavlin/dev/orange3env/lib/python3.5/site-packages/requests-2.9.1-py3.5.egg’,
‘/home/pavlin/dev/orange3env/lib/python3.5/site-packages/slumber-0.7.1-py3.5.egg’,
‘/home/pavlin/dev/orange3env/lib/python3.5/site-packages/Genesis_PyAPI-1.2.0-py3.5.egg’,
‘/usr/lib/python3.5/site-packages/qt_graph_helpers-0.1.3-py3.5-linux-x86_64.egg’,
‘/home/pavlin/dev/orange3-prototypes’,
‘/usr/lib/python3.5/site-packages’,
‘/home/pavlin/dev/orange3env/lib/python35.zip’,
‘/home/pavlin/dev/orange3env/lib/python3.5’,
‘/home/pavlin/dev/orange3env/lib/python3.5/plat-linux’,
‘/home/pavlin/dev/orange3env/lib/python3.5/lib-dynload’,
‘/usr/lib64/python3.5’,‘/usr/lib/python3.5’,
‘/usr/lib/python3.5/plat-linux’,
‘/home/pavlin/dev/orange3env/lib/python3.5/site-packages’,
‘/usr/lib/python3.5/site-packages/setuptools-18.7.1-py3.5.egg’,
‘/home/pavlin/.local/lib/python3.5/site-packages’]