导入问题,__init__.py 与 .ipynb

发布于 2025-01-19 22:43:44 字数 739 浏览 3 评论 0原文

我是一个初学者,在Python中正确组织了我的代码,我正在努力从.py script中的Main .ipynb中进行进口。

我的文件夹是按照以下方式组织的:

|   naive.ipynb
|   requirements.txt
|
+---data
|       DNA_train.txt
|       pseudomona.feather
|       pseudo_test.csv
|       pseudo_train.csv
|
+---model
|       dna_token.model
|
\---src
        token_dna_converter.py
        __init__.py

正如我所阅读的,为了能够从其他文件夹导入类,我应该添加__ INT __。py文件以从超级文件夹访问。在__ INIT __。py中,我

在.token_dna_converter导入tokendna 之后列出以下内容:

之后,我想在笔记本中调用此脚本,我尝试了以下内容:

>从token_dna_converter导入tokendna

但是,.ipynb无法检测到此内部“软件包” ... 我不知道为什么,我正在努力尝试解决这个问题。

有人知道我应该如何正确地调用此脚本吗?我会感谢一切!

I'm a beginner organizing my code properly in python and I am struggling a bit doing imports in my main .ipynb from a .py script.

My folder is organized as it follows:

|   naive.ipynb
|   requirements.txt
|
+---data
|       DNA_train.txt
|       pseudomona.feather
|       pseudo_test.csv
|       pseudo_train.csv
|
+---model
|       dna_token.model
|
\---src
        token_dna_converter.py
        __init__.py

As I have read, to be able to import classes from a different folder, I should add a __init__.py file to able access from a super folder. In the __init__.py I put the following:

from .token_dna_converter import tokenDNA

Afterwards, I want to call this script in a notebook and I have tried the following:

from token_dna_converter import tokenDNA

However, the .ipynb does not detect this inner "package"...
I don't know why and I am struggling to try to fix this.

Does anyone know how should I properly call this script? I would appreciate everything!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文