从 pydev 中的另一个项目导入
我已经四处寻找很长一段时间了,但我就是找不到答案。类似的问题涉及第三方库等的一些棘手案例,但我的情况似乎很简单。尽管如此,我还是不明白这是如何工作的。
我正在使用 Eclipse 3.5.2、Pydev 2.2.0,在 Ubuntu 11.04 机器上运行。
我的情况看起来很简单:我想编写一个包作为自己的项目,然后我想在另一个项目中使用这个包编写一个应用程序。
我应该如何设置 pydev 以便我可以拥有这两个项目“核心”(包)和“应用程序”(使用核心包),并从“应用程序”中执行以下操作:
import core
?
- 我已将核心添加到应用程序的项目参考中,但它不起作用 任何事物。
- 我已将 /core/ 添加到源文件夹(我必须强制这样做,因为它不是 显示在列表中),它不起作用(所以我将其删除)。
- 我已将 /full/path/to/core 添加到外部库,但它仍然不起作用。
我所说的“不起作用”,是指我总是得到“未解决的导入:核心”。
有想法吗?
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.
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.
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
?
- I have added core to the Project References of app but it doesn't do
anything. - I have added /core/ to the Source folders (I had to force for that because is was not
showing in the list), it didn't work (so I removed it). - I have added /full/path/to/core to the External Libraries, it still doesn't work.
By "doesn't work", I mean that I get an "unresolved import: core", always.
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您有 2 个项目的 PYTHONPATH 正确设置(通过源文件夹),那么只需添加项目引用就应该可以工作。
也许一个例子可以帮助...
例如:
然后编辑project2属性>项目引用并选择“project1”以便能够从项目2 访问项目1。
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...
E.g.:
and then edit the project2 properties > project references and select 'project1' to be able to access the project1 from the project2.
我有一段时间遇到同样的问题了。
现在我弄清楚了如何从其他项目中的模块和包导入类或函数。
我发现自己很愚蠢,因为这很容易。
结论!
您所要做的就是在“项目引用”、文件/属性/项目引用中检查项目名称。
就导入用法而言,引用其他项目与将所有文件或模块放入当前项目目录中相同。
我在 Windows 7 上使用 liclipse_1.0.0_win32.x86_64。
让我展示一下示例。
有两个项目 A 和 B,项目 A 有模块 a1.py 和包“M”。
您正在处理 B 项目并检查以下项目树中的引用 A 项目。
现在您可以像下面一样访问项目 A。
事实上,python import 语句对我来说有点奇怪,你可以找到其他方法来做同样的事情。
此外,如果你想从 Linux 命令行运行 b1.py 请参阅此。
I had been in same problem for a while.
Now I figured it out how I can import class or function from module and package in other projects.
I found myself dumb from this because it is ever easy.
Conclusion!
All you have to do is just to check the project name in 'Project References', File/Properties/Project References.
In terms of import usage, referencing other project is same as you put all files or modules in your current project directory.
I am using liclipse_1.0.0_win32.x86_64 on Windows 7.
Let's me show examples.
There are two project A and B and the project A has module a1.py and package 'M'.
You are working on B project and check reference A project in following project tree.
Now you can access project A like following.
In fact python import statement is little bit odd for me that you can find other way to do same thing.
In addition, if you want to run b1.py from Linux command line see this.
我没有通过添加项目引用来实现此功能。但是,我通过首先删除然后将 pydev 项目性质添加到项目中,然后设置项目引用来使其工作。
I did not get this working by adding a project reference. However, I got it working by first removing and then adding the pydev project nature to the project, and then, set the project reference.