Installing matplotlib for python3 on Ubuntu

喜欢而已 提交于 2019-12-13 19:19:04

问题


I'm running Ubuntu 12.04, and I need to use matpltlib in Python 3.2.3. I successfully installed it using

sudo apt-get install python-matplotlib

But now it works only in Python 2.7, which seems to be the default version:

$ python2
Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> 

But python 3 doesn't work:

$ python3
Python 3.2.3 (default, Feb 27 2014, 21:33:50) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named matplotlib
>>> 

Also, my python command seems to be 'broken':

$ python
bash: /usr/bin/python: No such file or directory

Any help is appreciated!


回答1:


In case anyone else stumbles upon this, just use

sudo apt-get install python3-matplotlib

There are many packages involved with matplotlib and using apt-get instead of pip this is the officially recommended approach.




回答2:


if you are in virtualenv example: workon cv #cv is my virtualenv name

$ workon cv
$ pip install matplotlib


来源:https://stackoverflow.com/questions/24449195/installing-matplotlib-for-python3-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!