相关疑难解决方法(0)

Python3导入相对或绝对的正确方法?

我正在编写一个 python 模块neuralnet。它在 Python2 中一切正常,但在 Python3 中导入失败。

这是我的代码结构。

neuralnet/
    __init__.py
    train.py         # A wrapper to train (does not define new things)
    neuralnet.py     # Defines the workhorse class neuralnet
    layer/
        __init__.py
        inlayer.py       # Defines input layer class
        hiddenlayer.py

application/         # A seperate application (not part of the package)
   classify.py       # Imports the neuralnet class from neuralnet.py
Run Code Online (Sandbox Code Playgroud)

train.py需要导入neuralnet.py 的neuralnet类。

neuralnet.py需要导入layers/inlayer.py

(我更喜欢相对进口。)

我有一个不同的应用程序 ( classify.py) 需要导入这个模块。我在哪里...

from neuralnet.neuralnet import neuralnet
Run Code Online (Sandbox Code Playgroud)

我尝试了几种导入方式。要么我得到一个错误(主要是像 parent 这样的神秘未导入)

  1. 运行 …

python import package python-2.7 python-3.x

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

import ×1

package ×1

python ×1

python-2.7 ×1

python-3.x ×1