PyDev for Eclipse - 解析Python依赖关系(未解析的导入) [英] PyDev for Eclipse - Resolve Python dependencies (unresolved imports)

查看:969
本文介绍了PyDev for Eclipse - 解析Python依赖关系(未解析的导入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PyDev作为我的IDE作为我的IDE和pip作为我的包管理工具,运行virtualenv。

I am using PyDev for Eclipse as my IDE and pip as my package management tool, running virtualenv.

每次我想在我的项目中使用/包含一些新的库或新的依赖项,我将它们添加到 pip-require 文件中。依赖关系安装在我的虚拟环境中,运行 pip install -r pip-require 后,没有问题。

Every time I want to use/include some new libraries or new dependencies in my project, I add them into the pip-requires file. The dependencies are installed in my virtual environment with no problem after running pip install -r pip-requires.

My Env


  • Ubuntu 12.04

  • Eclipse的PyDev 2.7.1.2012100913

  • Python 2.7.3

  • Eclipse indigo

  • Ubuntu 12.04
  • PyDev for Eclipse 2.7.1.2012100913
  • Python 2.7.3
  • Eclipse indigo

更新:我的Pydev设置

问题:


  • eclipse / pydev 不知道在虚拟环境中添加的新库。我不得不手动将.egg源文件夹添加到eclipse项目的PYTHONPATH中,以便解决所有未解决的导入,这非常令人讨厌!可以以更简单的方式解决python依赖问题吗?

  • eclipse/pydev knows nothing about the new libraries being added in my virtual env. I had to manually add the .egg source folder into eclipse project's PYTHONPATH one by one in order to resolve all the unresolved imports which was very annoying! Can the python dependencies be resolved in a easier manner?

更新:


  • 我发现如果我使用虚拟env Env / bin / python 作为解释器,屏幕截图显示,一些基本模块没有解决在日食中,例如我应该使用默认的 / usr / bin / python 作为解释器,只需添加虚拟的env, import copy,import json site-package 到PYTHONPATH?所以我可以解析两个标准的python库(例如json)和我自己的项目依赖关系?

  • I found that if I use virtual env Env/bin/python as the interpreter as the screenshot indicates, some of the basic modules are not resolved in eclipse, eg. import copy, import json etc. should I use default /usr/bin/python as interpreter and just add virtual env site-package to the PYTHONPATH? so that I can resolve both standard python libraries(eg. json) and my own project dependencies?

推荐答案

确保您的系统PYTHONPATH包含site-packages文件夹,当您选择python解释器你的virtualenv。就像快照一样。

Make sure your system PYTHONPATH include the site-packages folder when you choose python interpreter from your virtualenv. Just like the snapshot.

然后您不需要将它们逐个添加到PYTHONPATH中。您将需要重新启动eclipse(刷新不起作用)。新的模型将被添加。

Then you don't need to add them one by one into PYTHONPATH. You will need to restart eclipse (Refresh doesn't work). New models will be added.

更新:
我检查了virtualenv中的PYTHONPATH。我发现sys.path中还有一些其他路径。它们是系统默认的python安装位置。这些路径包括基本模型,如 copy json

PS:我的环境是Max OSX 10.8。请通过 print sys.path

PS: My environment is Max OSX 10.8. Please check the output of your own platform by print sys.path

/Users/username/.virtualenvs/test/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg
/Users/username/.virtualenvs/test/lib/python2.7/site-packages/pip-1.1-py2.7.egg
/Users/username/.virtualenvs/test/lib/python27.zip
/Users/username/.virtualenvs/test/lib/python2.7
/Users/username/.virtualenvs/test/lib/python2.7/plat-darwin
/Users/username/.virtualenvs/test/lib/python2.7/plat-mac
/Users/username/.virtualenvs/test/lib/python2.7/plat-mac/lib-scriptpackages
/Users/username/.virtualenvs/test/lib/python2.7/lib-tk
/Users/username/.virtualenvs/test/lib/python2.7/lib-old
/Users/username/.virtualenvs/test/lib/python2.7/lib-dynload
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/username/.virtualenvs/test/lib/python2.7/site-packages



我认为这是virtualenv的要求。您需要将这些路径添加到pydev系统PYTHONPATH中。然后可以使用这些基本模块。

I think this is the requirement of virtualenv. You need to add these paths into pydev system PYTHONPATH. Then you can use these basic modules.

这篇关于PyDev for Eclipse - 解析Python依赖关系(未解析的导入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆