我有一个如下所示的项目目录结构
|project
|-__init__.py
|-src
|- __init.py__
|- features
|- __init.py__
|- clean_data.py
|-notebooks
|- notebook.ipynb

主目录名为project,我在该目录下有两个目录- src和notebook。
我想要导入notebook.ipynb文件中功能目录(位于src下)下的模块clean_data.py。
我试过这个:
from ..src.features import clean_data 因为所有目录都作为软件包,每个目录中都有init.py文件。
但是它抛出了一个错误。我花了相当多的精力试图弄清楚这一点,但我不确定为什么我会得到这个错误。根据这篇文章,我似乎正确地访问了这个模块
mportError Traceback (most recent call last)
<ipython-input-23-11fd29e06b4c> in <module>()
----> 1 from ..src.features import clean_data
ImportError: attempted relative import with no known parent package发布于 2020-10-26 18:57:31
这是我代码的一部分,看看这个:
from domain_pricing.domains import *
from domain_pricing.conversion_rate import *我正在从domain_pricing文件夹导入domains.py和conversion_rate.py。
你应该做的是:
from src.features import clean_data
from src.data import another_module您不需要.或..作为基于Unix的系统路径目录。您需要直接调用该文件夹。
https://stackoverflow.com/questions/64535557
复制相似问题