Virtualenv 与 Eclipse (Galileo)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1145374/
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
Virtualenv with Eclipse (Galileo)
提问by Adam Nelson
Does anybody have directions for getting Eclipse (Galileo), PyDev, and Virtualenv working together? I'm specifically trying to run Pinax but any instructions are fine.
有没有人有让 Eclipse (Galileo)、PyDev 和 Virtualenv 一起工作的方向?我特别想运行 Pinax,但任何说明都很好。
I thought I had it (and even blogged everything but the final step - interactive debugging) and still there is no solution. I'm specifically on OS X but any answer should be sufficient. This is the best resource I've found so far:
我以为我已经做到了(甚至除了最后一步 - 交互式调试之外的所有内容都在博客上写了),但仍然没有解决方案。我专门在 OS X 上,但任何答案都应该足够了。这是迄今为止我找到的最好的资源:
http://blog.vlku.com/index.php/2009/06/10/djangoeclipse-with-code-complete-screencast/
http://blog.vlku.com/index.php/2009/06/10/djangoeclipse-with-code-complete-screencast/
回答by Filip Dupanovi?
I'd disagree with having to go through all the hassle of creating and maintaining a separate workspace for every virtual environment.
我不同意必须为每个虚拟环境创建和维护单独的工作区的所有麻烦。
All you need to do is set up a separate interpreter per virtualenv and make sure the project is using it.
您需要做的就是为每个 virtualenv 设置一个单独的解释器,并确保项目正在使用它。
Along with your standard interpreters such as Python 2.5, Python 2.6, Python 3.1you'll also add some more along the lines My Django Website, My Cool Project, My Other Cool Project--where each interpreter will have all the PYTHONPATH
entries as it's virtualenv would provide.
除了Python 2.5、Python 2.6、Python 3.1等标准解释器外,您还将添加更多内容My Django Website, My Cool Project, My Other Cool Project -- 其中每个解释器都将拥有所有PYTHONPATH
条目,因为它是 virtualenv会提供。
回答by DrBloodmoney
What problems are you having? The key is having separate workspaces for each project. Then select the python interpreter for that workspace to the one created for the virtualenv. Then you should be set.
你有什么问题?关键是每个项目都有单独的工作区。然后选择该工作区的python解释器到为virtualenv创建的解释器。那么你应该被设置。
回答by ColinMasters
My instructions for creating a Django Virtual Environment which works with Eclipse are as follows;
我创建与 Eclipse 一起使用的 Django 虚拟环境的说明如下;
Note: The instructions are for OSX Mountain Lion, but should work with other operating systems. I have collated this information from various sources and would appreciate any suggestions or comments. I will assume you have python, virtualenv and eclipse set up on your system.
注意:这些说明适用于 OSX Mountain Lion,但也适用于其他操作系统。我从各种来源整理了这些信息,并希望得到任何建议或意见。我假设你的系统上设置了 python、virtualenv 和 eclipse。
Open a terminal, move to the location you would like to have your eclipse workspace and;
打开一个终端,移动到你想拥有 eclipse 工作区的位置;
- mkdir projectenv
- cd project env
- virtualenv venv --distribute
- source venv/bin/activate
- mkdir projectenv
- cd 项目环境
- virtualenv venv --distribute
- 源 venv/bin/激活
Now, lets install the dependencies;
现在,让我们安装依赖项;
- pip install Django psycopg2 dj-database-url (Your needs may vary from mine)
- pip install Django psycopg2 dj-database-url (你的需求可能与我的不同)
Now we will start the Django project and commit to git;
现在我们将启动 Django 项目并提交到 git;
- django-admin.py startproject myproject
- pip freeze > requirements.txt
- git init; git add; git commit -m myproject (Please have a .gitignore file with venv and *pyc in it before doing this step)
- django-admin.py startproject myproject
- pip冻结>需求.txt
- 混帐初始化;git 添加;git commit -m myproject(在执行此步骤之前,请准备一个包含 venv 和 *pyc 的 .gitignore 文件)
Our django project is set up and ready to go, so now open eclipse and at the workspace selector, click browse and select the projectenv folder (i.e. the folder which contains the venv folder, the myproject folder and the requirements.txt folder) and click open.
我们的 django 项目已设置并准备就绪,因此现在打开 eclipse 并在工作区选择器处,单击浏览并选择 projectenv 文件夹(即包含 venv 文件夹、myproject 文件夹和 requirements.txt 文件夹的文件夹),然后单击打开。
Go to File, Import, General, Existing Folder as New Project and select the myproject folder, click finish. Your project will now appear in the package explorer - you should now switch to the PyDev perspective if not already on it.
转到文件、导入、常规、现有文件夹作为新项目并选择 myproject 文件夹,单击完成。您的项目现在将出现在包浏览器中 - 如果还没有,您现在应该切换到 PyDev 透视图。
Right click on the main myproject folder in the package explorer, go down to PyDev and select 'Set as PyDev project'. Eclipse will now prompt you to set up the interpreter and will take you to the preferences window. Click New, and select the interpreter in /venv/bin/ select python, not python2.7 and click ok.
右键单击包资源管理器中的主 myproject 文件夹,转到 PyDev 并选择“设置为 PyDev 项目”。Eclipse 现在将提示您设置解释器并带您进入首选项窗口。点击新建,在/venv/bin/中选择解释器,选择python,而不是python2.7,点击ok。
You will get a list of libs, leave them as they are and click finish, you will get a warning, but click proceed anyway.
您将获得一个库列表,保持原样并单击完成,您将收到警告,但仍单击继续。
Now, click on New Folder in the bottom half of the prefs window and select /venv/lib/, click ok, then click apply, then click ok.
现在,单击首选项窗口下半部分的新建文件夹并选择 /venv/lib/,单击确定,然后单击应用,然后单击确定。
Finally, right click on manage.py and Run As, Run Configurations. In the Arguments tab, type;
最后,右键单击 manage.py 和 Run As,Run Configurations。在参数选项卡中,键入;
- runserver --noreload
- 运行服务器 --noreload
then click Apply and then Close.
然后单击应用,然后关闭。
That should be that, when you want to add an app, do so on the command line as you normally would using manage.py startapp myapp (if you install the Aptana Studio plugin, you can get a terminal window inside eclipse), right click the main project folder in eclipse and hit refresh, everything will be there. When you want to debug, set your breakpoints, hit Debug As python manage.py (the config you set up earlier) and when you hit a code breakpoint, Eclipse fires you into the debug perspective.
应该是这样,当你想添加一个应用程序时,像往常一样在命令行上添加 manage.py startapp myapp(如果你安装了 Aptana Studio 插件,你可以在 eclipse 中得到一个终端窗口),右键单击eclipse 中的主项目文件夹并点击刷新,一切都会在那里。当您想要调试时,设置断点,点击 Debug As python manage.py(您之前设置的配置),当您点击代码断点时,Eclipse 会将您带入调试透视图。
I find this gives me the perfect mix, it means I can write a lot of stuff on the command line as normal, but because it's set up in Eclipse, when things aren't going my way, I can fire up eclipse and do some real debugging!
我发现这给了我完美的组合,这意味着我可以像往常一样在命令行上写很多东西,但是因为它是在 Eclipse 中设置的,当事情没有按照我的方式进行时,我可以启动 eclipse 并做一些真正的调试!
I hope this helps.
我希望这有帮助。
回答by Dingle
Not sure about Galileo since I have upgraded to Helios.
自从我升级到 Helios 后,对 Galileo 不确定。
It's easy to setup Project->PyDev - Interpreter/Grammar -> Interpreter based on different projects. When configure the interpreter to point to virtualenv's python interpreter, Pydev doesn't automatically inherit the system python's path, therefore it's the user's duty to select appropriate PYTHONPATH. But you can always go back to edit that in Preferences->Pydev->Interperter - Python -> Libraries tab.
根据不同的项目设置 Project->PyDev - Interpreter/Grammar -> Interpreter 很容易。当将解释器配置为指向virtualenv 的python 解释器时,Pydev 不会自动继承系统python 的路径,因此用户有责任选择合适的PYTHONPATH。但是你总是可以在 Preferences->Pydev->Interperter - Python -> Libraries 选项卡中返回编辑它。
回答by Dan
Based on the information here (and others found when I was trying to solve the same problem you had), I put together a post with step-by-step instructions here.
根据此处的信息(以及在我尝试解决您遇到的相同问题时发现的其他信息),我在此处整理了一篇包含分步说明的帖子。
The short answer, as the Doctor says, is to make each virtualenv correspond to a workspace - so when you create a new one of the former, you create a new one of the latter exclusively to use with it.
正如医生所说,简短的回答是使每个 virtualenv 对应于一个工作区 - 因此,当您创建前者的一个新的时,您会创建一个专门用于它的新的后者。