[英]python path during development of a package
Let's say my project structure looks like this: 假设我的项目结构如下所示:
app/
main.py
modules/
__init__.py
validation.py
configuration.py
modules package contains reusable code. modules包包含可重用的代码。 main.py executes main application logic.
main.py执行主应用程序逻辑。
When I try this in main.py 当我在main.py中尝试这个时
from modules import validation
I get an error which says that import inside of the validation failed. 我收到一个错误,表示验证中的导入失败。 Validation tries to import configuration and I get 'no module named configuration'
验证尝试导入配置,我得到'没有模块命名配置'
I am using Anaconda distribution on windows. 我在Windows上使用Anaconda发行版。
What is the best way of handling PYTHONPATH during development of the package ? 在开发包装时处理PYTHONPATH的最佳方法是什么?
Is there a way to utilize virtualenv (or conda env) in order to get package, that is in development,on the PYTHONPATH without changing sys.path from the code ? 有没有办法利用virtualenv(或conda env)来获取PYTHONPATH中的包,而不是从代码中更改sys.path ?
What is the preferred practice when developing a package ? 开发包装时的首选做法是什么?
I've also tried adding modules (folder) package to the lib/site-packages but it still didn't work. 我也尝试将模块(文件夹)包添加到lib / site-packages,但它仍然无效。
Change your import in validation.py
to: 将
validation.py
的导入更改为:
from . import configuration
This is needed for Python 3 but also works with Python 2. 这是Python 3所必需的,但也适用于Python 2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.