Skip to content Skip to sidebar Skip to footer

Adding Modules To Python3

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 tak

Solution 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.

Solution 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.

Solution 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

Post a Comment for "Adding Modules To Python3"