如何使用Eclipse和PyDev将现有文件添加到项目中

时间:2023-01-13 12:26:41

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.

我能找到的只是导入文件层次结构,但导致导入不完整或导入我不想要的文件夹。任何帮助,将不胜感激。

3 个解决方案

#1


11  

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).

单击Next,再次单击Next(不需要引用其他项目)。

Enter database details and click Finish.

输入数据库详细信息并单击Finish。

Your Eclipse/Django project is ready to go.

您的Eclipse / Django项目已准备就绪。

#2


3  

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.

假设您的系统中有某些源,而不是工作区文件夹中的源。

  1. Install Pydev (Help > Install New Software...), use http://pydev.org/updates as the source.
  2. 安装Pydev(帮助>安装新软件...),使用http://pydev.org/updates作为源。
  3. Create a new empty Pydev project. Name it how you want, but it can be like your actual application name.
  4. 创建一个新的空Pydev项目。根据需要命名,但它可以像您的实际应用程序名称一样。
  5. 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.
  6. 文件>新建>其他... - 在Pydev中选择“链接源文件夹”或类似文件。导航到sources文件夹,然后选择我们刚刚创建的目标项目。

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 Package Explorer”),将能够编辑等,但您无法运行此(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> Set as Django project(请参阅此处: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等源代码项目)。

#3


0  

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]/

├──[projectname] /

├── [yourappname]/

├──[yourappname] /

│ ├── init.py

│├──init.py

│ ├── settings.py

│├──settings.py

│ ├── urls.py

│├──urls.py

│ └── wsgi.py

│└──wsgi.py

└── manage.py

└──manage.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)享受

#1


11  

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).

单击Next,再次单击Next(不需要引用其他项目)。

Enter database details and click Finish.

输入数据库详细信息并单击Finish。

Your Eclipse/Django project is ready to go.

您的Eclipse / Django项目已准备就绪。

#2


3  

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.

假设您的系统中有某些源,而不是工作区文件夹中的源。

  1. Install Pydev (Help > Install New Software...), use http://pydev.org/updates as the source.
  2. 安装Pydev(帮助>安装新软件...),使用http://pydev.org/updates作为源。
  3. Create a new empty Pydev project. Name it how you want, but it can be like your actual application name.
  4. 创建一个新的空Pydev项目。根据需要命名,但它可以像您的实际应用程序名称一样。
  5. 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.
  6. 文件>新建>其他... - 在Pydev中选择“链接源文件夹”或类似文件。导航到sources文件夹,然后选择我们刚刚创建的目标项目。

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 Package Explorer”),将能够编辑等,但您无法运行此(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> Set as Django project(请参阅此处: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等源代码项目)。

#3


0  

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]/

├──[projectname] /

├── [yourappname]/

├──[yourappname] /

│ ├── init.py

│├──init.py

│ ├── settings.py

│├──settings.py

│ ├── urls.py

│├──urls.py

│ └── wsgi.py

│└──wsgi.py

└── manage.py

└──manage.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)享受