简体   繁体   English

如何将预先存在的 python 项目导入 Eclipse?

[英]How do I import a pre-existing python project into Eclipse?

I am using eclipse for python.我正在为 python 使用 eclipse。 How do I import an existing project into eclipse in the current workspace.如何将现有项目导入到当前工作区中的 eclipse 中。

Thanks谢谢

New Project新项目

Dont use default Location不要使用默认位置

Browse to existing project location ...浏览到现有项目位置...

if its an existing eclipse project with project files that have correct paths for your system you can just open the .proj file ...如果它是一个现有的 eclipse 项目,项目文件的系统路径正确,你可以打开 .proj 文件......

In my case when i am trying to import my existing perforce project , it gives error no project found on windows machine.在我的情况下,当我尝试导入我现有的 perforce 项目时,它给出了在 Windows 机器上找不到项目的错误。 On linux i was able to import project nicely.在 linux 上,我能够很好地导入项目。

For Eclipse Kepler, i have done like below.对于 Eclipse Kepler,我做了如下操作。

  1. Open eclipse in pydev perspective.在 pydev 视角下打开 eclipse。
  2. Create a new pydev project in your eclipse workspace with the same name which project you want to import.在您的 eclipse 工作区中创建一个新的 pydev 项目,其名称与您要导入的项目相同。
  3. By now in your eclipse workspace project dir , you must be having .project and .pydevproject files.到目前为止,在您的 eclipse 工作区项目目录中,您必须拥有 .project 和 .pydevproject 文件。
  4. Copy these two files and paste it to project dir which you want to import.复制这两个文件并将其粘贴到要导入的项目目录中。
  5. Now close and delete the pydev project you created and delete it from local disk as well.现在关闭并删除您创建的 pydev 项目,并将其从本地磁盘中删除。
  6. Now you can use import utility to import project in eclipse.现在您可以使用导入实用程序在 Eclipse 中导入项目。

At time of writing none of the given answers worked.在撰写本文时,给出的答案均无效。

This is how it's done:这是它的完成方式:

  1. Locate the directory containing the Pydev project找到包含 Pydev 项目的目录
  2. Delete the PyDev project files (important as Eclipse won't let you create a new project in the same location otherwise)删除 PyDev 项目文件(很重要,否则 Eclipse 不会让您在同一位置创建新项目)
  3. In Eclipse, File->New->Pydev Project在 Eclipse 中,File->New->Pydev Project
  4. Name the project the same as your original project将项目命名为与原始项目相同的名称
  5. For project contents, browse to location containing Pydev project对于项目内容,浏览到包含 Pydev 项目的位置
  6. Select an interpreter选择口译员
  7. Follow rest of the menu through按照菜单的其余部分

Other answers using Eclipse project importing result in Pydev loosing track of packages, turning them all into folders only.使用 Eclipse 项目导入的其他答案导致 Pydev 失去对包的跟踪,仅将它们全部转换为文件夹。

This does loose any project settings previously set, please edit this answer if it can be avoided.这确实会丢失之前设置的任何项目设置,如果可以避免,请编辑此答案。 Hopefully Pydev devs will add project import functionality some time.希望 Pydev 开发人员会在某个时候添加项目导入功能。

  • make sure pydev interpreter is added, add otherwise确保添加了 pydev 解释器,否则添加
  • windows->preferences->Pydev->Interpreter-Python windows->preferences->Pydev->Interpreter-Python

  • then create new pydev project,然后创建新的 pydev 项目,

  • give the same name给相同的名字
  • then don't use default location, browse to point the project location.然后不要使用默认位置,浏览以指向项目位置。

Copy these two files from some existing pydev eclipse project to root folder of new project which you want to import in eclipse.将这两个文件从一些现有的 pydev eclipse 项目复制到要在 eclipse 中导入的新项目的根文件夹。 .project .pydevproject .project .pydevproject

Open .project file in notepad and change name to your_project_name.在记事本中打开 .project 文件并将名称更改为 your_project_name。 If you don't have these files then you can create them yourself.如果您没有这些文件,那么您可以自己创建它们。

Open eclipse, click File -> Import.打开eclipse,点击文件->导入。 New window will open.将打开新窗口。 Now select 'Existing Projects into Workspace' under 'General' and click Next.现在选择“常规”下的“现有项目到工作区”,然后单击“下一步”。 On new window browse to project root directory and select root folder.在新窗口浏览到项目根目录并选择根文件夹。 Then click finish.然后点击完成。

Check this tutorial for complete solution .查看本教程以获取完整的解决方案

Following are the steps以下是步骤

  • Select pydev Perspective选择pydev透视
  • right click on the project pan and click "import"右键单击项目盘,然后单击“导入”
  • From the list select the existing project into workspace.从列表中选择现有项目进入工作区。
  • Select root directory by going next通过下一步选择根目录
  • Optionally you can select to copy the project into您可以选择将项目复制到

thanks谢谢

First of all make sure that you have the same Python interpreter configured as the project has.首先确保您配置了与项目相同的 Python 解释器。 You can change it under:您可以在以下位置更改它:

Window > Preferences > PyDev > Interpreters > Python Interpreters窗口 > 首选项 > PyDev > 解释器 > Python 解释器

As long the project was created using Eclipse you can use import functionality.只要项目是使用 Eclipse 创建的,您就可以使用导入功能。 Go to:去:

File > Import... > General > Existing Projects into Workspace文件 > 导入... > 常规 > 现有项目到工作区

Choose Select root directory: and browse to your project location.选择Select root directory:并浏览到您的项目位置。 Click Finish and you are done.单击完成,您就完成了。

I just suffered through this problem for a few hours.我刚刚经历了这个问题几个小时。 My issue may have been different than yours...Pydev did not show up as an import option (as opposed to C projects).我的问题可能与你的不同...... Pydev 没有显示为导入选项(与 C 项目相反)。 My solution is to drag and drop.我的解决方案是拖放。 Just create a new project (name it the same as your old) and then drop your old project into the new project folder as displayed in eclipse...3 hours later and it's drag and drop...只需创建一个新项目(将其命名为与旧项目相同的名称),然后将旧项目放入 eclipse 中显示的新项目文件夹中...... 3 小时后,拖放......

This can easily be done if you keep you project in a git repository.如果您将项目保存在 git 存储库中,则可以轻松完成此操作。 The following is working with Linux but should be ok with Windows as well:以下适用于 Linux,但也适用于 Windows:

Clone your project from the repository:从存储库克隆您的项目:

git clone https://url/of/project/file.git

(if you don't keep your project on a free git server like github or bitbucket, you can create a new local repository by changing directory into an existing project folder and typing git init ) (如果你没有将你的项目保存在像 github 或 bitbucket 这样的免费 git 服务器上,你可以通过将目录更改为现有项目文件夹并输入git init来创建一个新的本地存储库)

Then open eclipse and go to File > Import > Git > Projects from Git > Existing local repository > (select your project or add it) > Next > Finish然后打开 eclipse 并转到 File > Import > Git > Projects from Git > Existing local repository >(选择您的项目或添加它)> Next > Finish

After following steps outlined by @Shan, if the folders under the root folder are not shown as packages,遵循@Shan 概述的步骤后,如果根文件夹下的文件夹未显示为包,

  • Right-click on the root folder in PyDev Package Explorer右键单击 PyDev Package Explorer 中的根文件夹
  • Select PyDev > Set as source-folder选择 PyDev > 设置为源文件夹

It will add the root folder to the PYTHONPATH and now the folders will appear as packages它将根文件夹添加到 PYTHONPATH,现在文件夹将显示为包

Create a new project with in Eclipse and copy the two files .project and .pydevproject to root directory from your Python project, then edit the .project file and replace the name project by the name of your python project.在 Eclipse 中创建一个新项目并将两个文件.project.pydevproject从您的 Python 项目复制到根目录,然后编辑 .project 文件并将名称 project 替换为您的 Python 项目的名称。

Then go and import your python project👉👉然后去导入你的python项目👉👉

要编辑的 .project 文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM