2

I'm trying to create a development environment where modules are divided into libraries and applications.
The application needs to import a module that is not installed as a package into the main python packages.
Both the application and the libraries are continuously modified.

This is the directory layout of the files. Files from one project may be reused by other projects, and thus cannot be in the same directory tree.

projA\lib\util.py
projA\lib\other.py
projB\lib\another.py
projC\src\app1\app1.py

So far, the best I could come up with is the following, which causes problems for IDEs code completion because of the dynamic imports

# app1.py
import sys
sys.path.append('../../../projA/lib')
import util

Is there a better way of doing this?

4

2 回答 2

2

如何使用virtualenv并将您的其他项目作为库安装在虚拟系统路径中。

大多数 Python IDE 都支持 virtualenv,并且在代码完成方面没有问题。

这也是一个很好的做法,可以轻松分发您的项目和管理依赖项。

于 2013-04-14T16:34:52.530 回答
2

如果您不想使用 virtualenv 或动态导入,

您可以将模块路径添加到PYTHONPATH环境变量。

蟒蛇路径

注意:您可能必须创建此环境变量,假设您使用的是 Windows 操作系统,您可以使用(从命令行):

setx PYTHONPATH folder1;folder2;etc

设置

于 2013-04-14T16:37:41.843 回答