【问题标题】:How to import a python file with out of scope dependencies in iPython如何在 iPython 中导入具有超出范围依赖项的 python 文件
【发布时间】: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


【解决方案1】:

this 有帮助吗?我们需要告诉 Python 在哪些目录中搜索模块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    相关资源
    最近更新 更多