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

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

问题描述

我在Linux(Ubuntu 14.04)机器上运行了Pycharm 4.除了系统python外,我还安装了Anaconda.让两者很好地协同工作似乎有点问题... PyCharm为virtualenvpip提供了一些有趣的集成,但是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结合使用?不仅可以作为替代解释器,例如将PyCharm指向项目解释器的Anaconda Python二进制文件,还可以创建,提供/激活和取消激活虚拟环境,在这些虚拟环境中添加/删除程序包等.

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 一样.

创建一个新的Conda环境:

Create a new Conda environment:

conda create --name foo pandas bokeh

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激活新环境,请转到文件>设置>项目>解释器,在项目解释器字段(小齿轮)中选择 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 install scikit-learn

conda install scikit-learn

确定...在设置中返回您的口译员.神奇的是,PyCharm现在可以看到scikit学习了!

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

反之亦然,即当您在PyCharm中pip安装另一个软件包时,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 list

conda list

该列表现在包括请求,并且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天全站免登陆