python -V
Python 3.7.6
which python
python: aliased to python3.7
which python3.7
/path/to/virtualenvfolder/bin/python3.7
文件夹结构
src
|-- __init__.py
|-- migrations
|-- env.py
from config import DB, DB_HOST, DB_USER, DB_PASS, DB_PORT, DB_DRIVER
错误
File "src/migrations/env.py", line 13, in <module>
from config import DB, DB_HOST, DB_USER, DB_PASS, DB_PORT, DB_DRIVER
ModuleNotFoundError: No module named 'config'
但如果改成
from src.config import DB, DB_HOST, DB_USER, DB_PASS, DB_PORT, DB_DRIVER
-- __init__.py
from config import DB, DB_HOST, DB_USER, DB_PASS, DB_PORT, DB_DRIVER
它的工作原理。