问题
I am trying to use the library matplotlib, but can't get it to work with python3. The python 2.7.3 interpreter I have finds it without a problem though. What steps do I need to take for python3 to have access to this library?
回答1:
To handle your Python packages, I suggest you rather use pip than your OS package manager.
To install pip, just follow the instructions.
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python ez_setup.py
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py
should be enough.
Be sure to use python3 command if the python on your path is version 2.x
After having install pip, you will be able to download and install the packages from Pypi by running
pip install PACKAGE_NAME
so for instance, for matplotlib
pip install matplotlib
If pip is already installed for Python2, the command may be pip3
or pip-3.x
to install packages for Python3.
If you have errors while installing matplotlib, make sure that you have the necessary packages to compile it. On Ubuntu I suppose
sudo apt-get install build-essential
should be enough for a basic installation though.
回答2:
You need to make sure it is in the path for your python3 and that your version of matplotlib is compatible with python3. What I would do is open you python2.7 and python3 interpreters and enter the following:
>>>import sys
>>>print sys.path
and see how the outputs compare. You also could download and compile the matplotlib with python3 instead of python2.7. You would just need to run the setup.py file with python3 instead of python2.7.
回答3:
You should be able to install Python 3 matplotlib for Ubuntu using
sudo apt-get install python3-matplotlib
EDIT: This package exists from Ubuntu 13.04. If you have an older Ubuntu, then you'll have to either
install it manually: https://gist.github.com/mlongval/4950532
or install it from a third-party repository: http://www.math.univ-paris13.fr/~cuvelier/mainsu22.html
来源:https://stackoverflow.com/questions/20534556/adding-modules-to-python3