在 PyCharm 中使用 (Ana)conda [英] Using (Ana)conda within PyCharm

查看:43
本文介绍了在 PyCharm 中使用 (Ana)conda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Linux (Ubuntu 14.04) 机器上运行着 Pycharm 4.除了系统python,我还安装了Anaconda.让两者很好地一起玩似乎有点问题...... PyCharm 为 virtualenvs 和 pip 提供了一些有趣的集成,但 Anaconda Python 发行版似乎更喜欢在这两个活动中使用自己的 conda 工具.

I've got Pycharm 4 running on my Linux (Ubuntu 14.04) machine. In addition to the system python, I've also got Anaconda installed. Getting the two to play nicely together seems to be a bit of a problem... PyCharm provides some interesting integration for virtualenvs and pip, but the Anaconda Python distribution seems to prefer using its own conda tool for both activities.

是否有一种相对简单/无痛的方法可以将 conda 与 PyCharm 结合使用?不仅仅是作为替代解释器,即在项目解释器的 Anaconda Python 二进制文件中指向 PyCharm,而且能够创建、源/激活和停用虚拟环境,在这些虚拟环境中添加/删除包等.

Is there a relatively simple/painless way to be able to use conda in conjunction with PyCharm? Not just as an alternative interpreter i.e. point PyCharm at the Anaconda Python binary for a project interpreter, but to be able to create, source/activate and deactivate virtual envs, add/remove packages in those virtual envs, etc.

或者我是否必须在使用 Anaconda(并拥有比系统附带的更新和最新的 Python)和能够最大程度地使用 PyCharm 的功能之间做出选择?

Or am I going to have to choose between using Anaconda (and having a more recent and up-to-date python than may come with the system), and being able to use PyCharm's features to their fullest extent?

推荐答案

我知道现在已经晚了,但我认为澄清一些事情会很好:PyCharm 和 Conda 和 pip 可以很好地协同工作.

I know it's late, but I thought it would be nice to clarify things: PyCharm and Conda and pip work well together.

只需从命令行管理 Conda.一旦发生变化,PyCharm 会自动注意到变化,就像使用 pip 一样.

Just manage Conda from the command line. PyCharm will automatically notice changes once they happen, just like it does with pip.

创建一个新的 Conda 环境:

Create a new Conda environment:

conda create --name foo pandas bokeh

此环境位于 conda_root/envs/foo 下.你的 python 解释器是 conda_root/envs/foo/bin/pythonX.X 而你所有的站点包都在 conda_root/envs/foo/lib/pythonX.X/site-packages.这与 pip 虚拟环境中的目录结构相同.PyCharm 认为没有区别.

This environment lives under conda_root/envs/foo. Your python interpreter is conda_root/envs/foo/bin/pythonX.X and your all your site-packages are in conda_root/envs/foo/lib/pythonX.X/site-packages. This is same directory structure as in a pip virtual environement. PyCharm sees no difference.

现在要从 PyCharm 激活您的新环境,请转到 file > settings > project > interpreter,在项目解释器字段(小齿轮)中选择 Add local 和追捕你的python解释器.恭喜!您现在拥有包含熊猫和散景的 Conda 环境!

Now to activate your new environment from PyCharm go to file > settings > project > interpreter, select Add local in the project interpreter field (the little gear wheel) and hunt down your python interpreter. Congratulations! You now have a Conda environment with pandas and bokeh!

现在安装更多软件包:

conda 安装 scikit-learn

好的...返回设置中的解释器.神奇的是,PyCharm 现在看到了 scikit-learn!

OK... go back to your interpreter in settings. Magically, PyCharm now sees scikit-learn!

并且反之亦然,即当您在 PyCharm 中 pip install 另一个包时,Conda 会自动通知.假设您已经安装了请求.现在列出当前环境中的 Conda 包:

And the reverse is also true, i.e. when you pip install another package in PyCharm, Conda will automatically notice. Say you've installed requests. Now list the Conda packages in your current environment:

conda 列表

该列表现在包括请求,并且 Conda 已正确检测到(第 3 列)它是通过 pip 安装的.

The list now includes requests and Conda has correctly detected (3rd column) that it was installed with pip.

这对于像我这样在软件包不是纯 python 的情况下试图摆脱 pip/virtualenv 安装问题的人来说绝对是个好消息.

This is definitely good news for people like myself who are trying to get away from the pip/virtualenv installation problems when packages are not pure python.

注意:我在 Linux 上运行 PyCharm 专业版 4.5.3.对于 Windows 用户,将命令行中的 替换为 GUI 中的 (并将正斜杠替换为反斜杠).没有理由它也不适合你.

NB: I run PyCharm pro edition 4.5.3 on Linux. For Windows users, replace in command line with in the GUI (and forward slashes with backslashes). There's no reason it shouldn't work for you too.

PyCharm5 支持 Conda!在社区版中也是如此.

PyCharm5 is out with Conda support! In the community edition too.

这篇关于在 PyCharm 中使用 (Ana)conda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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