【发布时间】:2018-05-13 06:13:41
【问题描述】:
我正在使用 PyCharm CE 开发一个类似这样结构的项目:
test_python/
|-- app
| |-- __init__.py
| |-- mymodule.py
| |-- mymodule.pyc
| `-- test_mymodule.py
|-- config.py
`-- tests
|-- __init__.py
|-- test_config.py
`-- test_models.py
当我尝试运行 test_config.py 等测试脚本时,我得到:
$ python tests/test_config.py
Traceback (most recent call last):
File "tests/test_config.py", line 1, in <module>
from config import app_config
ImportError: No module named config
我已经阅读了很多其他 SO 帖子,这些帖子谈到在所有作为包的目录中都需要一个 init.py 文件(我已经这样做了)。许多人还建议使用sys.path。我对后一种方法的问题是我以前从未干预过这些路径。我不确定我的开发环境设置是否发生了变化,但这里是:
Python 2.7 | macOS 塞拉利昂 | PyCharm CE
我尝试使用 virtualenv 安装虚拟环境,但没有发现差异。这是github 上的示例项目,如果您想自己运行它
【问题讨论】:
标签: python python-2.7 configuration virtualenv setup-project