Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I install the latest versions of NumPy/Scipy/Matplotlib/IPython/Pandas on Ubuntu

Users sometimes need to know how to install a newer version of Pandas than their OS package manager offers. Pandas requires NumPy, and works best with SciPy, Matplotlib and IPython.

How can I install the latest versions of NumPy/Scipy/Matplotlib/IPython/Pandas?

like image 351
unutbu Avatar asked Jan 23 '15 13:01

unutbu


People also ask

How do I install additional Python libraries such as NumPy SciPy pandas and Matplotlib?

Install Numpy, Pandas, Scipy, Matplotlib By PIP Command. First, make sure pip has been installed on your OS. If it is not installed, please refer article How To Install Python/Pip On Windows. Run pip install command to install related packages. Run pip uninstall command to uninstall related packages.

How do I download Matplotlib on Ubuntu?

If you are using the Python version that comes with your Linux distribution, you can install Matplotlib via your package manager, e.g.: Debian / Ubuntu: sudo apt-get install python3-matplotlib. Fedora: sudo dnf install python3-matplotlib. Red Hat: sudo yum install python3-matplotlib.


2 Answers

Using Ubuntu, here is how to install the entire NumPy/Scipy/Matplotlib/IPython/Pandas stack from Github in a virtualenv using Python2.7:

Note: The instructions below install the latest development version of each package. If you wish to install the latest tagged version, then after git clone, inspect the tags available with

git tag

and select the version you wish to install with

git checkout tag-name

Install virtualenv and virtualenvwrapper:

sudo apt-get install python-virtualenv
sudo pip install virtualenvwrapper

# edit ~/.bashrc to include
source /usr/share/virtualenvwrapper/virtualenvwrapper.sh

# edit ~/.profile to include
export WORKON_HOME=$HOME/.virtualenvs

# You may have to log out then log back in to make the change effective

Make a virtualenv

mkvirtualenv --system-site-packages dev
workon dev

# If you want to make this virtual environment your default Python,
# edit ~/.bashrc to include
workon dev

Add site-packages to sys.path:

add2virtualenv $USER/.virtualenvs/dev/lib/python2.7/site-packages

Install Cython

pip install -U Cython

Install git

sudo apt-get install git

Install NumPy

cd ~/src
git clone https://github.com/numpy/numpy.git

sudo apt-get install python-dev build-essential  
sudo apt-get install libatlas-base-dev libatlas3gf-base

# ensure clean build
# this is not necessary the first time, but useful when upgrading
cd ~/src/numpy
/bin/rm -rf ~/src/numpy/build
cdsitepackages && /bin/rm -rf numpy numpy-*-py2.7.egg-info

cd ~/src/numpy
python setup.py build --fcompiler=gnu95
python setup.py install

Install SciPy

cd ~/src
git clone https://github.com/scipy/scipy.git

# ensure clean build
cd ~/src/scipy
/bin/rm -rf ~/src/scipy/build
cdsitepackages && /bin/rm -rf scipy scipy-*-py2.7.egg-info

cd ~/src/scipy
git clean -xdf
python setup.py install

Install Matplotlib dependencies

pip install -U pyparsing
pip install -U six
pip install -U python-dateutil
pip install -U pytz
sudo apt-get install libzmq-dev
pip install -U tornado pygments pyzmq 
pip install -U nose
sudo apt-get install python-qt4 python-qt4-doc python-pyside python-cairo python-wxgtk2.8 python-gtk2 dvipng

apt-cache depends python-matplotlib | awk '/Depends:/{print $2}' | xargs dpkg --get-selections
sudo apt-get build-dep python-matplotlib

Install Matplotlib

cd ~/src/
git clone https://github.com/matplotlib/matplotlib

# ensure clean build
cd ~/src/matplotlib
/bin/rm -rf ~/src/matplotlib/build
cdsitepackages && /bin/rm -rf matplotlib* mpl_toolkits

# compile and install
cd ~/src/matplotlib
python setup.py build
python setup.py install

Install IPython

cd ~/src
git clone https://github.com/ipython/ipython.git

# ensure clean build
cd ~/src/ipython
/bin/rm -rf ~/src/ipython/build
cdsitepackages && /bin/rm -rf ipython-*-py2.7.egg

cd ~/src/ipython
python setupegg.py install

Install Pandas

cd ~/src
git clone https://github.com/pydata/pandas.git
cd ~/src/pandas

# update
git fetch origin
git rebase --interactive origin/master

# ensure clean build and install
/bin/rm -rf ~/src/pandas/{build,dist} && cdsitepackages && /bin/rm -rf pandas* && cd ~/src/pandas && python setup.py build_ext --inplace && python setup.py install 

Updating:

The advantage of the git approach is that it provides a way to always keep these packages up-to-date:

cd ~/src/package-name
git fetch origin
git rebase --interactive origin/master

Follow the instructions above to ensure a clean build, and then rebuild and reinstall the package.

Shorthand for using pip with GitHub directly

The above steps to clone and install packages can be automated to an extent with pip. For example, we can also install NumPy like this:

pip install git+git://github.com/numpy/numpy.git

The updating would then be just

pip install numpy --upgrade --force-reinstall

--force-reinstall flag may be needed because pip checks the version from PyPI and doesn't update if the current version isn't smaller.

like image 166
12 revs, 3 users 91% Avatar answered Oct 05 '22 14:10

12 revs, 3 users 91%


Via the Anaconda distribution:

Download and install

wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
chmod +x miniconda.sh
./miniconda.sh -b
export PATH=/home/travis/miniconda/bin:$PATH
conda update conda --yes

Install just the packages in the title in their own environment:

conda create --name myenv --yes python=3.4 pandas matplotlib ipython-notebook
source activate myenv

Note: I believe anaconda supports Python versions 2.6, 2.7, 3.3, and 3.4.

like image 38
Paul H Avatar answered Oct 05 '22 15:10

Paul H