问题描述
我一直在四处寻找,但我找不到答案.类似的问题与第三方库的一些棘手案例有关,但我的情况似乎很简单.尽管如此,我还是无法弄清楚这是如何工作的.
I've been looking around for quite some time but I just can't find the answer. Similar questions relate to some tricky cases with third party libraries and all, but my situation seems to be textbook-simple. Nevertheless I can't figure out how this works.
我使用的是 Eclipse 3.5.2、Pydev 2.2.0,在 Ubuntu 11.04 机器上运行.
I'm using Eclipse 3.5.2, Pydev 2.2.0, running on an Ubuntu 11.04 machine.
我的情况看起来很简单:我想写一个包作为自己的项目,然后我想在另一个项目中使用这个包编写一个应用程序.
My case seems simple: I want to write a package as its own project, and then I want to write an application using this package in another project.
我应该如何设置 pydev 以便我可以拥有这两个项目core"(包)和app"(使用核心包),并从app"内部执行:
How should I setup pydev so that I can have this two projects "core" (the package) and "app" (which uses the core package), and from within "app" do:
import core
?
- 我已将核心添加到应用程序的项目参考中,但它没有做任何东西.
- 我已将/core/添加到源文件夹中(我不得不强制这样做,因为它不是显示在列表中),它不起作用(所以我删除了它).
- 我已将/full/path/to/core 添加到外部库,但它仍然不起作用.
不起作用"是指我总是收到未解析的导入:核心".
By "doesn't work", I mean that I get an "unresolved import: core", always.
想法?
推荐答案
如果您有 2 个项目并正确设置了 PYTHONPATH(通过源文件夹),它应该只需添加一个项目引用即可.
Provided you have 2 projects with the PYTHONPATH properly set (through source folders), it should work just adding a project reference.
也许一个例子可以帮助...
Maybe an example can help...
例如:
project1
project1/src <-- this should be set as the source folder
project1/src/core
project1/src/core/__init__.py
project2
project2/src <-- this should be set as the source folder
project2/src/app
project2/src/app/__init__.py
然后编辑 project2 属性 > 项目引用并选择project1",以便能够从 project2 访问 project1.
and then edit the project2 properties > project references and select 'project1' to be able to access the project1 from the project2.
这篇关于从 pydev 中的另一个项目导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!