python - ModuleNotFoundError:没有名为“my_app”的模块。即使使用 __init__.py
问题描述
这是我的项目结构。
├─demo_data
├─findb
│ └─__pycache__
├─management
└─tw_equity
├─migrations
│ └─__pycache__
└─__pycache__
现在我尝试将演示数据插入到我的模型中。所以我commands.py
为这个过程创造。
# ./management/commands.py
from datetime import datetime
from tw_equity.models import (
TradingDate,
Basic,
Price,
Holder,
)
with open('demo_data/trading_date.csv') as f:
for row in f:
data = datetime.strptime(row, "%Y-%m-%d").date()
trading_date = TradingDate(
trading_date=data
)
trading_date.save()
print('Insert Successfully.')
但是错误不断出现。
(Findb) C:\Users\ycyta\python-django-Findb>management\commands.py
Traceback (most recent call last):
File "C:\Users\ycyta\python-django-Findb\management\commands.py", line 2, in <module>
from tw_equity.models import (
ModuleNotFoundError: No module named 'tw_equity'
已经试过了
python manage.py shell
,一切都很好。
(Findb) C:\Users\ycyta\python-django-Findb>python manage.py shell
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from tw_equity.models import TradingDate
>>> TradingDate
<class 'tw_equity.models.TradingDate'>
- 以前大多数类似的问题都被关注
__ini__.py
,但我已经有了。
感谢您的帮助。
解决方案
推荐阅读
- c++ - 我的 EditDistance Recursive 代码中的 char 类型有问题
- python - 如何基于数据框创建另一个向量
- java - 如何将包含 HTML 元素的 Java 字符串解析为 JsonObject?
- node.js - Mongoose 5 异步连接问题
- linux - 安装 npm 模块时出现 Ubuntu/巨大错误
- c# - 并发冲突:UpdateCommand 影响了预期的 1 条记录中的 0 条(Windows 窗体中具有 4 列的简单 1 行表)
- haskell - 使用 foldr 构造 foldl
- java - 执行示例 Flink kafka 消费者
- java - java/hibernate - 如何使用注释映射三个表/实体(休眠错误未映射到单个属性)
- css - HTML:滚动时粘性标题会跳跃一点