猿问

路径中有模块的ModuleNotFoundError

我有以下文件结构


.

└── text_classifier

    ├── Experiment.py

    ├── __init__.py

    ├── constants.py

    ├── hyperparameters

    │   ├── Hyperparameter.py

    │   └── __init__.py

    ├── models

    │   ├── __init__.py

    │   ├── han.py

    │   └── model.py

    ├── trainers

    │   ├── __init__.py

    │   ├── dataset_trainer.py

    │   └── trainer.py

    └── utils

        ├── __init__.py

        ├── default_conf.yml

        ├── tf_utils.py

        └── utils.py

我想import text_classifier从Ipython控制台。


text_classifier/__init__.py 包含


import builtins

import sys

import os


sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))

sys.path.append(os.path.dirname(os.path.dirname(__file__)))

sys.path.append(os.path.dirname(__file__))

sys.path.append(__file__)


print('\n'.join(sys.path))


from .experiment import Experiment

from .hyperparameters import HP


try:

    from IPython.lib import deepreload


    builtins.reload = deepreload.reload

except:

    pass

但是,import text_classifier as tcl从与该位置相同的位置运行将text_classifier产生以下结果:


/Users/victor/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python36.zip

/Users/victor/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6

/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/lib-dynload

/Users/victor/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6/site-packages

/Users/victor/.pyenv/versions/3.6.4/lib/python3.6/site-packages

/Users/victor/.pyenv/versions/3.6.4/Python.framework/Versions/3.6/lib/python3.6/site-packages/IPython/extensions

/Users/victor/.ipython

/Users/victor/Documents/documentation

/Users/victor/Documents/documentation/han

/Users/victor/Documents/documentation/han/text_classifier

/Users/victor/Documents/documentation/han/text_classifier/__init__.py

ModuleNotFoundError: No module named 'text_classifier.experiment'

显然,text_classifier它位于路径(...documentation/han/text_classifier)中。任何想法?


PIPIONE
浏览 426回答 1
1回答
随时随地看视频慕课网APP

相关分类

Python
我要回答