python - 如何在cmd中使用包执行python代码?
问题描述
project
__init__.py
module_1
module_2
test_pkg
__init__.py
test_module_1 ----> import module_1
test_module_2 ----> import module_2
我正在使用上述结构,它在 Eclipse IDE 中运行良好。但我无法从命令提示符运行。
普通的python模块可以如下执行,
python test_code.py
但是当我运行 test_module_1 或 test_module_2 时显示以下错误,
Traceback (most recent call last):
File "test_module_1.py", line 8, in <module>
from project.module_1 import module_1
ModuleNotFoundError: No module named 'module_1'
如何做到这一点?
解决方案
推荐阅读
- django - 如何在Django的登录页面中将用户名的标签更改为“用户名/电子邮件”
- android - Android如何将固定大小的芯片文本居中?
- mongodb - 每次添加新的子文档时,mongoDB 是否会将文档移动到新的内存位置?
- arrays - 如何在 VBA 中创建 2D 数组或自定义类的集合?
- c++ - 获取具有指定值的元素的索引
- c++ - 为什么按位运算符在使用与整数中提供的相同位数计算可能的最大范围时会产生错误
- sql - SQL Server:DATEADD 2 月 29 日不返回 1 月 30,31 日
- swift - 如何快速识别以编程方式生成的 TextView?
- json - 为 sagemaker 上的 tensorflow 服务模型提供输入时出错。{'error': "缺少 'inputs' 或 'instances' 键"}
- scala - Scala中的函数定义添加的无法识别的字段