如何为 anaconda 1.9.1 和 Python 3.3.4 安装 Matplotlib?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22053852/
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
How to install Matplotlib for anaconda 1.9.1 and Python 3.3.4?
提问by User1551892
I am configuring Anaconda 1.9.1 together with Python 3.3.4 and I am unable to setup Matplotlib for anaconda environment when I try to add package using Pycharm. I also tried to install from Matplotlib.exe file which I downloaded from its website. I can not change the installation directory in that case. I would like to know that is there a way to tackle this issue.
我正在将 Anaconda 1.9.1 与 Python 3.3.4 一起配置,当我尝试使用 Pycharm 添加包时,我无法为 anaconda 环境设置 Matplotlib。我还尝试从我从其网站下载的 Matplotlib.exe 文件中进行安装。在这种情况下,我无法更改安装目录。我想知道有没有办法解决这个问题。
采纳答案by Paul H
If you're using anaconda, your default environment is Python 2.7. You need to create a new environment and install matplotlib in there.
如果您使用 anaconda,则默认环境为 Python 2.7。您需要创建一个新环境并在其中安装 matplotlib。
In a command prompt, do the following (saying yes to the questions):
在命令提示符下,执行以下操作(对问题说是):
conda create --name mpl33 python=3.3 matplotlib ipython-notebook
activate mpl33
ipython notebook
You should be able to import matplotlib when the notebook server comes up.
当笔记本服务器启动时,您应该能够导入 matplotlib。
- The first command simultaneously creates the environment and install the listed packages.
- The second command activates the new environment by prepending its location to the system path
- The third command just starts the ipython notebook so that you can test out everything
- 第一个命令同时创建环境并安装列出的包。
- 第二个命令通过将其位置添加到系统路径来激活新环境
- 第三个命令只是启动 ipython 笔记本,以便您可以测试所有内容
I don't know how pycharm works, but my guess is that you'll have to tell it to look for the right python that you want to use. In this case it'll be something like: C:/Users//anaconda/envs/mpl33. In any case, the command prompt should display the path when you activate the environment.
我不知道 pycharm 是如何工作的,但我的猜测是你必须告诉它寻找你想要使用的正确 python。在这种情况下,它将类似于:C:/Users//anaconda/envs/mpl33。在任何情况下,当您激活环境时,命令提示符都应显示路径。
Once you've activated your environment, you can install more packages like this:
激活环境后,您可以安装更多这样的软件包:
conda install pandas=0.12
conda install pyodbc statsmodels
You can specific version numbers of packages like the first command or simply accept the latest available version (default)
您可以像第一个命令一样指定软件包的版本号,或者只是接受最新的可用版本(默认)
回答by fantabolous
Assuming you've already installed a 3.x python env in anaconda, this one line should do the trick:conda install matplotlib -n name
where name is the name you previously gave to your python 3 anaconda env. If you're not sure of the name you gave it, it will be the name of a subdir in the Anaconda\envs directory.
假设您已经在 anaconda 中安装了 3.x python env,这一行应该可以解决问题:conda install matplotlib -n name
其中 name 是您之前为 python 3 anaconda env 提供的名称。如果您不确定给它起的名字,它将是 Anaconda\envs 目录中子目录的名称。
Background: I recently went through the same trouble with matplotlib not getting installed by default by anaconda when I added a full python 3 env, even though it's meant to. The above line solved it for me; it gave me the following warnings so it seems likely that the two different available versions caused it to initially install neither. However it allowed me to choose the one I wanted, and then everything worked great.
背景:我最近遇到了同样的问题,当我添加完整的 python 3 env 时,anaconda 默认没有安装 matplotlib,即使它是故意的。上面的行为我解决了它;它给了我以下警告,所以这两个不同的可用版本似乎很可能导致它最初没有安装。然而,它允许我选择我想要的那个,然后一切都很好。
Warning: 2 possible package resolutions:
[u'dateutil-2.1-py33_2.tar.bz2', u'matplotlib-1.3.1-np18py33_1.tar.bz2', u'numpy-1.8.0-py33_0.tar.bz2', u'pyparsing-2.0.1-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u'python-3.3.5-0.tar.bz2', u'pytz-2013b-py33_0.tar.bz2', u'six-1.6.1-py33_0.tar.bz2']
[u'dateutil-2.1-py33_2.tar.bz2', u'matplotlib-1.3.1-np17py33_1.tar.bz2', u'numpy-1.7.1-py33_3.tar.bz2', u'pyparsing-1.5.6-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u'python-3.3.5-0.tar.bz2', u'pytz-2013b-py33_0.tar.bz2', u'six-1.6.1-py33_0.tar.bz2' ]
警告:2 种可能的包分辨率:
[u'dateutil-2.1-py33_2.tar.bz2'、u'matplotlib-1.3.1-np18py33_1.tar.bz2'、u'numpy-1.8.0-py33_0.tar.bz2' , u'pyparsing-2.0.1-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u'python-3.3.5-0.tar.bz2', u'pytz- 2013b-py33_0.tar.bz2',u'six-1.6.1-py33_0.tar.bz2']
[u'dateutil-2.1-py33_2.tar.bz2',u'matplotlib-1.3.1-np17py33_1.tar。 bz2', u'numpy-1.7.1-py33_3.tar.bz2', u'pyparsing-1.5.6-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u' python-3.3.5-0.tar.bz2', u'pytz-2013b-py33_0.tar.bz2', u'six-1.6.1-py33_0.tar.bz2']
回答by Mona Jalal
conda install -c conda-forge matplotlib

