Search code examples
python-3.xubuntu-12.04python-module

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 take for python3 to have access to this library?


Solution

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