让 PyC​​harm 识别 Anaconda 的 SciPy [英] Getting PyCharm to recognize Anaconda's SciPy

查看:26
本文介绍了让 PyC​​harm 识别 Anaconda 的 SciPy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 PyCharm IDE 中使用 SciPy 库(在 Mac OSX Lion 机器上).SciPy 网站写道,Mac 用户最简单的安装方法是安装 Anaconda(或等效发行版).我使用了 Anaconda 安装程序,它在我的主文件夹中创建了一个 anaconda 目录,在那里我找到了一个包含所需包的 lib/python2.7/site-packages 目录.然而,PyCharm 并不知道这一切,SciPy 导入语句仍未解决.

I need to use the SciPy libraries inside the PyCharm IDE (on a Mac OSX Lion machine). The SciPy website writes that the simplest installation method for Mac users is to install Anaconda (or an equivalent distro). I used the Anaconda installer, and it created an anaconda directory in my home folder, where I find a lib/python2.7/site-packages directory with the required packages. However, PyCharm is not aware of all this and the SciPy import statements remain unresolved.

我的问题是如何让 PyC​​harm 与 A​​naconda 一起工作?

My question is then how to make PyCharm work with Anaconda?

推荐答案

我仍然接受 Python 生态系统和 PyCharm,所以对以下内容持保留态度,但在 读了一点,我想我会写一个详细的解释.

I'm still coming to terms with the Python ecosystem and PyCharm, so take the following with a grain of salt, but after reading up a bit, I thought I'd write a detailed explanation.

在安装过程中,Anaconda 将默认的 Python 解释器更改为 ~/anaconda/bin/python.这个解释器配置了一个 sys.path,默认为 ~/anaconda/lib 中的库.像 python 的 pip 这样的包管理器使用运行它们的解释器来确定安装包的路径,所以在安装 Anaconda 之后,所有通过 pip 或其他方法安装的包都将放置在 ~/anaconda/lib 中的某个位置.即,即使不使用 virtualenv 之类的东西,每个 Python 解释器都有自己的生态系统,使用不同的解释器运行 pip 会将包安装到不同的目录中.

During installation, Anaconda changes the default Python interpreter to ~/anaconda/bin/python. This interpreter is configured with a sys.path that defaults to the libraries in ~/anaconda/lib . Package managers like python's pip use the interpreter that's running them to determine the path in which to install packages, so after Anaconda is installed, all packages installed via pip or other methods will be placed somewhere inside ~/anaconda/lib. i.e. even without using something like virtualenv, every Python interpreter has its own ecosystem and running pip with different interpreters will install packages into different directories.

PyCharm 在 Project Settings-->Project Interpreter-->Python Interpreters 屏幕中处理所有这些.要让 PyC​​harm 知道 Anaconda 发行版,您需要将 Anaconda python 解释器添加到 Project Interpreter-->Python Interpreters 列表并使其成为项目的默认值.然后,PyCharm 将找到安装在 Anaconda 解释器生态系统 (~/anaconda/lib) 中的所有包,并在下方窗格的 packages 下列出它们.它还会提示您为该解释器安装 setup_tools 和 pip,一旦您这样做,您就可以使用下方窗格中的 install 按钮向 Anaconda 生态系统添加更多包.

PyCharm handles all this in the Project Settings-->Project Interpreter-->Python Interpreters screen. To make PyCharm aware of the Anaconda distribution, you need to add the Anaconda python interpreter to the Project Interpreter-->Python Interpreters list and make it the default for the project. PyCharm will then locate all packages installed in Anaconda's interpreter ecosystem (~/anaconda/lib) and list them under packages in the lower pane. It will also prompt you to install setup_tools and pip for that interpreter, and once you do that you'll be able to use the install button in the lower pane to add more packages to the Anaconda ecosystem.

添加 Anaconda 解释器后,您还可以使用上方窗格工具栏中的 virtualenv 按钮创建一个从 Anaconda 解释器环境继承的 virtualenv.这样您就可以以不影响全球 Anaconda 发行版的方式安装新软件包.

Once you've added the Anaconda interpreter, you can also use the virtualenv button from the toolbar on the upper pane to create a virtualenv that inherits from the Anaconda interpreter's environment. That way you can install new packages in a way that would not affect the global Anaconda distribution.

这篇关于让 PyC​​harm 识别 Anaconda 的 SciPy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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