如何使用 Eclipse 和 PyDev 将现有文件添加到项目中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9194222/
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
How to add existing files to project using Eclipse and PyDev
提问by ballaw
I'm fairly new to Eclipse and I have been trying to import a Django project I had made separate from Eclipse. It would be most helpful if someone could give me a step-by-step guide on how to import my Django project.
我对 Eclipse 还很陌生,我一直在尝试导入一个与 Eclipse 分开的 Django 项目。如果有人能给我一个关于如何导入我的 Django 项目的分步指南,那将是最有帮助的。
All I was able to find was to import the file hierarchy but that led to either incomplete imports or importing folders I didn't want. Any help would be appreciated.
我所能找到的只是导入文件层次结构,但这导致导入不完整或导入了我不想要的文件夹。任何帮助,将不胜感激。
回答by Furbeenator
If it is not an Eclipse project, then you have to create a new Eclipse project in the root of the Django project.
如果不是Eclipse项目,那么就得在Django项目的根目录下新建一个Eclipse项目。
Go to File menu, click New > Project.
转到文件菜单,单击新建 > 项目。
Select Pydev Django Project, assuming you have added the PyDev and PyDev Django plugins to Eclipse. Click Next.
选择 Pydev Django Project,假设您已将 PyDev 和 PyDev Django 插件添加到 Eclipse。点击下一步。
Give your project a name, then browse to the location where your Django project exists (where your manage.py, settings.py, and url.py is).
为您的项目命名,然后浏览到您的 Django 项目所在的位置(您的 manage.py、settings.py 和 url.py 所在的位置)。
Select a Python Grammar to use (anything prior to 3 - there are some issues with 3 and Django).
选择要使用的 Python 语法(3 之前的任何语法 - 3 和 Django 存在一些问题)。
Click Next, and Next again (don't need to reference other projects).
单击下一步,然后再单击下一步(不需要引用其他项目)。
Enter database details and click Finish.
输入数据库详细信息,然后单击完成。
Your Eclipse/Django project is ready to go.
您的 Eclipse/Django 项目已准备就绪。
回答by Tomasz Gandor
This is a moderately painful process, but I have gone through it in Kepler (Eclipse 4.3), with the recent Pydev version.
这是一个相当痛苦的过程,但我已经在 Kepler (Eclipse 4.3) 和最近的 Pydev 版本中完成了它。
Assuming you have the sources somewhere on your system, not in the workspace folder.
假设您在系统上的某处拥有源代码,而不是在工作区文件夹中。
- Install Pydev (Help > Install New Software...), use http://pydev.org/updatesas the source.
- Create a new emptyPydev project. Name it how you want, but it can be like your actual application name.
- File > New > Other... - in Pydev choose "Link sources folder" or similar. Navigate to your sources folder, and select the target project that we just created.
- 安装 Pydev(帮助 > 安装新软件...),使用http://pydev.org/updates作为源。
- 创建一个新的空Pydev 项目。随意命名,但它可以像您的实际应用程序名称一样。
- 文件 > 新建 > 其他... - 在 Pydev 中选择“链接源文件夹”或类似的。导航到您的源文件夹,然后选择我们刚刚创建的目标项目。
Now you'll see the files in the tree ("Pydev Package Explorer"), will be able to edit etc, but you can't run this (manage.py runserver) or run unit tests (manage.py test).
现在您将看到树中的文件(“Pydev 包资源管理器”),将能够编辑等,但您不能运行它(manage.py runserver)或运行单元测试(manage.py test)。
To do this, right click the project and choose Pydev > Set as Django project (see here: http://pydev.org/manual_adv_django.html)
为此,请右键单击该项目并选择 Pydev > 设置为 Django 项目(请参阅此处:http://pydev.org/manual_adv_django.html )
Now go to properties and configure the settings module, and path to your manage.py
.
现在转到属性并配置设置模块,以及您的manage.py
.
Caution: this is relative to your project directory in the workspace. Even if you type /path/to/my_django_project/manage.py
.
注意:这是相对于您在工作区中的项目目录。即使您键入/path/to/my_django_project/manage.py
.
So, I ended up doing this (bash):
所以,我最终这样做了(bash):
$ cd $HOME/workspace/my_django_project
$ ln -s /path/to/my_django_project
and left the configuration as "my_django_project/manage.py" and "settings".
(in Windows you could do the same within 1 Volume - using mklink /J
)
并将配置保留为“my_django_project/manage.py”和“settings”。(在 Windows 中,您可以在 1 个卷内执行相同的操作 - 使用mklink /J
)
Now, it all works like a dream - there is a "Django run configuration" for my project, the files get modified in the working copy checked out outside of workspace, unit test run nicely and all is fine. If I just were able to make Subclipse see my sources as a working copy, I'd be almost like on PyCharm (except for a Django Template syntax-highlighted autocompleting editor, richer code inspections, and the automatic recognition of such sources as a django project).
现在,这一切都像做梦一样 - 我的项目有一个“Django 运行配置”,文件在工作区之外检出的工作副本中得到修改,单元测试运行良好,一切都很好。如果我能够让 Subclipse 将我的源视为工作副本,我几乎就像在 PyCharm 上一样(除了 Django 模板语法突出显示的自动完成编辑器、更丰富的代码检查以及将此类源自动识别为 django项目)。
回答by Szakaria
i'have tried several solutions but the one that worked fine for me is the following :
我已经尝试了几种解决方案,但对我来说效果很好的解决方案如下:
1) create a new Django project in eclipse with the same name of the project you want to import
1)在eclipse中新建一个与要导入的项目同名的Django项目
2) verify that the imported project structure match Django structure:
2)验证导入的项目结构是否与Django结构匹配:
[projectname]/
[项目名]/
├── [projectname]/
├── [项目名称]/
├── [yourappname]/
├── [你的应用名称]/
│ ├── init.py
│ ├── init.py
│ ├── settings.py
│ ├── settings.py
│ ├── urls.py
│ ├── urls.py
│ └── wsgi.py
│ └── wsgi.py
└── manage.py
└── 管理.py
3) copy the imported project in eclipse workspace to replace the project you just created (since they have the same name) .
3) 将导入的项目复制到eclipse 工作区中,以替换您刚刚创建的项目(因为它们具有相同的名称)。
4) now go to eclipse and right click on the created project -> refresh
4)现在去eclipse并右键单击创建的项目->刷新
5) enjoy
5)享受