如何在 PyDev 中为基于 Django 的项目配置代码完成?
我正在玩一个基于 Django 框架的简单项目。 我的 IDE 是 PyDev/Eclipse。
我无法使 Django 代码的代码完成工作正常,但它对于标准 Python 库工作得很好。 我尝试将 Django 目录(在我的例子中为 C:\Program Files\Python26\Lib\site-packages\django)添加到 PyDev 级别上的 PYTHONPATH(Window->Preferences->PyDev->Interpreter - Python-> ;库)和项目级别(项目->属性->PyDev - PYTHONPATH) - 到目前为止还没有运气。
您能否告诉我这里缺少什么(最好不安装 PyDev 扩展)。
I am playing with a simple project based on Django framework. My IDE is PyDev/Eclipse.
I cannot make code completion work for Django code, but it works fine for standard Python libraries.
I tried to add Django dir (in my case C:\Program Files\Python26\Lib\site-packages\django) to PYTHONPATH both on PyDev level (Window->Preferences->PyDev->Interpreter - Python->libraries) and on a project level (Project->Properties->PyDev - PYTHONPATH) - no luck so far.
Can you please advise what I am missing here (preferably without installing PyDev extensions).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我再试一次。
Eclipse C:\test\eclipse
Python 2.6.2 C:\test\python-2.6.2 >
Django 1.0.2 Final 位于 C:\test\python-2.6.2\Lib\site-packages -> 只有实际的 django 文件夹,而不是文档、示例等。 我没有按照安装文件中的描述运行 setup.py 来完成此操作。
将 C:\test\python-2.6.2 和 C:\test\python-2.6.2\Lib\site-packages 添加到 PATH strong> 变量
如此处所述,我通过 Window > 在 Eclipse 中设置解释器 偏好> pydev > 翻译> Python。 这会自动在系统库下包含一大堆东西,例如 (C:\test\python-2.6.2\;C:\test\python-2.6.2\DLLs;C:\test\python-2.6.2\lib \站点包;....)。 还发现了一大堆强制内置函数。
然后我创建了一个新的“Pydev 项目”,添加了一个包,其中有一个带有类的新模块和一个导入该类并从中调用函数的模块。 在编写本文期间,多次按下 Crtl+Space,内置函数以及我的模块中的新内容通过代码完成显示。
Ok I give it another try.
Eclipse in C:\test\eclipse
Python 2.6.2 in C:\test\python-2.6.2
Django 1.0.2 final in C:\test\python-2.6.2\Lib\site-packages -> only the actual django folder not the docs, example, and so on. I did this without running setup.py as descriped in the INSTALL file.
Added C:\test\python-2.6.2 and C:\test\python-2.6.2\Lib\site-packages to the PATH variable
As described here I set the Interpreter in Eclipse by Window > preferences > pydev > Interpreter > Python. This automatically included a whole bunch of things under System libs like (C:\test\python-2.6.2\;C:\test\python-2.6.2\DLLs;C:\test\python-2.6.2\lib\site-packages;....). A whole bunch of Forced Builtins are also found.
Then I made a new "Pydev Project" added a package and there a new module with a class and a module which imports the class and calls a function from it. During writing this pressed Crtl+Space several times, and builtins as well as the new stuff from my Module where shown by code completion.
我建议 配置 pydev 以与 django 一起使用 和
Eclipse/Pyddev 入门
在后一个中有一个专门用于代码完成的部分其中提到了防火墙或 shell 超时的问题。 在另一节中,他提到了当(如您的情况)Eclipse 安装的文件路径中有空格时出现的问题
I suggest Configuring pydev to work with django and
Getting started Eclipse/Pyddev
In the latter one there is a section specifically for code completion which mentions a problem with firewall or shell timeout. And in another section he mentions problems when (as in your case) the eclipse installations has spaces in the filepath
我也解决了设置 PYTHONPATH 的问题。
在托盘Projects中,右键单击项目-> 特性
在 PYTHONPATH 配置中,您必须将包含项目的文件夹作为外部文件夹。
示例:
/var/www/my_project
PYTHONPATH=/var/www/
I solved setting the PYTHONPATH too.
In the pallet Projects, right-click on the project -> properties
In the PYTHONPATH configuration you have to put the folder that contains your project as a external folder.
Exemple:
/var/www/my_project
PYTHONPATH=/var/www/