为了账号安全,请及时绑定邮箱和手机立即绑定

路径中有模块的ModuleNotFoundError

路径中有模块的ModuleNotFoundError

PIPIONE 2021-03-28 16:43:28
我有以下文件结构.└── 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 builtinsimport sysimport ossys.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 Experimentfrom .hyperparameters import HPtry:    from IPython.lib import deepreload    builtins.reload = deepreload.reloadexcept:    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__.pyModuleNotFoundError: No module named 'text_classifier.experiment'显然,text_classifier它位于路径(...documentation/han/text_classifier)中。任何想法?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 425 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信