在 Eclipse (Helios) 中设置项目 Pydev PYTHONPATH 的最有效方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4324502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Most efficient way of setting up a project Pydev PYTHONPATH in Eclipse (Helios)?
提问by MdaG
I want to add all folders in my Pydev project to PYTHONPATH so that I can reap the benefits of easily seeing unused imports etc. To do this I seemingly have to add all folders manually including the subfolders, one by one. Is there any way to add them all at once (recursively) or am I doing this completely wrong?
我想将 Pydev 项目中的所有文件夹添加到 PYTHONPATH,以便我可以轻松查看未使用的导入等。为此,我似乎必须手动添加所有文件夹,包括子文件夹,一一添加。有没有办法一次(递归地)添加它们,或者我这样做完全错误?
Now I right click the project in the Navigatorand select Preferences. From there I go to Pydev-PYTHONPATHand finally I can add the folders.
现在我在Navigator 中右键单击该项目并选择Preferences。从那里我转到Pydev-PYTHONPATH,最后我可以添加文件夹。
回答by Fabio Zadrozny
Ok, just to give a proper answer, you should just add the folder(s) that you want to be in the PYTHONPATH as your source folder(s).
好的,只是为了给出正确的答案,您应该将您想要在 PYTHONPATH 中的文件夹添加为您的源文件夹。
So, if you have a structure such as
所以,如果你有一个结构,比如
/myproject
/myproject/src
/myproject/package
/myproject/package/__init__.py
/myproject/package2
/myproject/package2/__init__.py
You'd only want to add /myproject/src as your PYTHONPATH.
您只想将 /myproject/src 添加为您的 PYTHONPATH。
If you really had multiple folders to add there, you could edit the .pydevproject file (which is at the root of your project) and add multiple folders there at once (although as noted, you should only have few folders there, so, this is generally not needed -- although sometimes you may want that if you're adding multiple libraries to a folder or something alike).
如果你真的有多个文件夹要添加到那里,你可以编辑 .pydevproject 文件(它在你的项目的根目录)并一次在那里添加多个文件夹(尽管如上所述,你应该只有几个文件夹,所以,这个通常不需要 - 尽管有时如果您将多个库添加到文件夹或类似的东西,您可能需要这样做)。
The PyDev FAQexplains this properly on the items listed below:
该PyDev的常见问题解释了这个正确的下列项目:
How do I import existing projects/sources into PyDev?
How do I import existing projects/sources for a Django project into PyDev?
如何将现有项目/源导入 PyDev?
如何将 Django 项目的现有项目/源导入 PyDev?
回答by mihir
Check this out, this worked for me.
看看这个,这对我有用。
if you get an error “unresolved import: pydevd” try saving the file ‘manage.py' first. the error should go away.
If the error persists: you need to make sure pydev is in your PYTHONPATH. a) Go to Eclipse>Preferences>PyDev>Python Interpreter: b) Click New Folder> (mac)”/Applications/Eclipse/plugins/org.python.pydev_x.x.x.x/pysrc”
如果您收到错误“unresolved import: pydevd”,请先尝试保存文件“manage.py”。错误应该消失。
如果错误仍然存在:您需要确保 pydev 在您的 PYTHONPATH 中。a) 转到 Eclipse>Preferences>PyDev>Python Interpreter:b) 单击 New Folder> (mac)”/Applications/Eclipse/plugins/org.python.pydev_x.xxx/pysrc”
c) Click “Apply” This adds the folder that contains pydevd.py to your PYTHONPATH. Eclipse automatically adds that to your project's Python Library. This should resolve the problem and you can run it now.
c) 单击“应用”这会将包含 pydevd.py 的文件夹添加到您的 PYTHONPATH。Eclipse 会自动将其添加到项目的 Python 库中。这应该可以解决问题,您现在可以运行它。
https://djangounchain.files.wordpress.com/2012/12/screen-shot-2013-01-06-at-3-49-02-pm.png
https://djangounchain.files.wordpress.com/2012/12/screen-shot-2013-01-06-at-3-49-02-pm.png
回答by MikeW
(This should be a Comment to Fabio's answer, but insufficient rep)
(这应该是对 Fabio 的回答的评论,但代表不足)
(PyDev 2.7.1.2012100913)
(PyDev 2.7.1.2012100913)
Adding folders to the PythonPath does not work for EFS/Remote folders (rse://...)
将文件夹添加到 PythonPath 不适用于 EFS/远程文件夹 (rse://...)
When you click 'Apply' gives:
当您单击“应用”时,会显示:
An internal error occurred during: "Python Nature: rebuilding modules".
java.lang.NullPointerException