我有以下结构
.
├── module1
│ ├── __init__.py
│ └── start.py
├── module2
│ ├── __init__.py
│ └── settings.py
└── Pipfile
猫模块1 / start.py
from module2.settings import VAR
if __name__ == '__main__':
print(VAR)
猫模块2 / settings.py
VAR = 'foo'
如果我尝试运行程序,我会得到
pipenv shell
python module1/start.py
Traceback (most recent call last):
File "module1/start.py", line 1, in <module>
from module2.settings import VAR
ModuleNotFoundError: No module named 'module2'
要么
pipenv run python module1/start.py
Traceback (most recent call last):
File "module1/start.py", line 1, in <module>
from module2.settings import VAR
ModuleNotFoundError: No module named 'module2'
为什么pipenv无法正确设置PYTHONPATH?
最佳答案
我意识到我可以使用.env文件来设置PYTHONPATH并使pipenv使用它。
echo "PYTHONPATH=${PWD}" >> .env
关于python - Pipenv未设置PYTHONPATH,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52986500/