【发布时间】:2017-11-08 17:34:21
【问题描述】:
在虚拟环境中使用 iPython(python 2.7.13 和 iPython 0.31.1)我正在尝试测试我在目录中编写的一些代码,如下所示。
Root
Dir1
Dir2
NeedsTesting.py
Dir3
Dir4
Dependency1.py
在NeedsTesting.py 内部有一个Dependency1 的导入。当我在Dir2 目录中并尝试import NeedsTesting 时,我收到以下错误。
ImportError: No module named Dependency1.
当我回到 root 并尝试 import NeedsTesting.py 时,出现错误 ImportError: No Module named NeedsTesting.py。
当我尝试像from Dir1/Dir2 import NeedsTesting.py 这样调用文件时,我收到指向行中第一个/ 的语法错误。
我怎样才能使 iPython 可以在整个项目中找到模块,而不仅仅是直接级别?
【问题讨论】:
标签: python import directory ipython