简体   繁体   English

在 virtualenv 之外找不到项目模块

[英]Project module not found outside virtualenv

My project has basically an architecture like this:我的项目基本上有这样的架构:

src
├── __init__.py
├── main.py
└── core
    ├── __init__.py
    ├── module1.py
    └── module2.py

All __init__.py files are empty, in main.py I have a from src.core.module1 import stuff and I am running main.py from the src folder.所有__init__.py文件都是空的,在main.py我有一个from src.core.module1 import stuff main.py from src.core.module1 import stuff ,我从src文件夹运行main.py When I'm running it from my project virtual environment everything works fine, but outside of the virtual environment I have an ImportError: no module named src.core.module1 .当我从我的项目虚拟环境运行它时一切正常,但在虚拟环境之外我有一个ImportError: no module named src.core.module1 I cannot understand why, because this module is in the project, not related to the Python environment packages...我不明白为什么,因为这个模块在项目中,与Python环境包无关......

(Windows / Python 2.7.14) (Windows / Python 2.7.14)

Try from core.module1 import stuff .尝试from core.module1 import stuff You should not import src since you are in that location with your main.py already.您不应该导入src因为您已经在 main.py 所在的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM