Summary from building Python 3.4. * From source to building a scientific computing environment

When I tried to do something with Anaconda (https://store.continuum.io/cshop/anaconda/), I got angry with munmap_chunk (): invalid pointer when reading a large table with pandas, so I gave up. I built the Python 3.4 system from the source and built the environment for scientific calculation, so the summary.

Prepared environment

Python build

Before building the Python body, install the necessary libraries. Even if these are not included, the Python installation itself will pass safely, but later I will suffer from a not found error in the library and I will have to reinstall Python, so I will put it in first anyway. (Self-discipline)

$ sudo yum groupinstall --skip-broken "Development tools"
$ sudo yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

Build Python itself. (This time we will introduce the current latest version 3.4.2) This time, install it under / usr / local. Check the version from the following site. https://www.python.org/downloads/source/

$ wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
$ tar xzvf Python-3.4.2.tgz
$ cd Python-3.4.2
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make
$ sudo make install

Installation is complete if the following command can be executed.

$ which python3
/usr/local/bin/python3

If the Python build is successful, pip should be installed automatically, so check it with the following command.

$ which pip3
/usr/local/bin/pip3

Installation of various packages

Installation of packages for scientific calculations

Install the packages required to install Scipy in advance.

sudo yum install blas-devel lapack-devel

Except for specific packages, it can be introduced smoothly with pip3.

$ sudo /usr/local/bin/pip3 install nose pytest numpy scipy scikit-learn pandas

Install matplotlib

Install the packages required to install matplotlib in advance.

$ sudo yum install libpng-devel

When I try to install matplotlib with pip3, the build fails with the following message.

============================================================================

                        * The following required packages can not be built:

                        * freetype

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip_build_root/matplotlib
Storing debug log for failure in /root/.pip/pip.log

If you look closely at the error message, you will find the following message.

REQUIRED DEPENDENCIES AND EXTENSIONS
...
              freetype: no  [Requires freetype2 2.4 or later.  Found

                        2.3.11.]

In order to install matplotlib, freetype2 2.4 or higher is required, but it seems that 2.3.11 is included by default. Here, I decided to build freetype from source. The source can be downloaded from the following site. http://download.savannah.gnu.org/releases/freetype/

$ wget http://download.savannah.gnu.org/releases/freetype/freetype-2.5.3.tar.gz
$ tar xzvf freetype-2.5.3.tar.gz
$ cd freetype-2.5.3
$ ./configure
$ make
$ sudo make install

When I tried pip3 again after finishing up to this point, the following error occurred this time.

Downloading/unpacking matplotlib
  Downloading matplotlib-1.4.0.tar.gz (51.2MB): 51.2MB downloaded
  Running setup.py (path:/tmp/pip_build_root/matplotlib/setup.py) egg_info for package matplotlib
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip_build_root/matplotlib/setup.py", line 154, in <module>
        result = package.check()
      File "/tmp/pip_build_root/matplotlib/setupext.py", line 945, in check
        min_version='2.4', version=version)
      File "/tmp/pip_build_root/matplotlib/setupext.py", line 433, in _check_for_pkg_config
        if (not is_min_version(version, min_version)):
      File "/tmp/pip_build_root/matplotlib/setupext.py", line 166, in is_min_version
        return found_version >= expected_version
      File "/usr/local/lib/python3.4/distutils/version.py", line 76, in __ge__
        c = self._cmp(other)
      File "/usr/local/lib/python3.4/distutils/version.py", line 343, in _cmp
        if self.version < other.version:
    TypeError: unorderable types: str() < int()

After investigating this error, I found that it seems to be a known bug in Python 3.3 / 3.4 series. See the issue below for details. http://bugs.python.org/issue14894

Download the 14894.patch listed here and apply it to Python. (When will this change be applied to Python itself and released ...)

$ wget http://bugs.python.org/file25808/14894.patch
$ cd /usr/local/lib/python3.4/distutils/
$ sudo patch -p3 < /path/to/patch/14894.patch 

Matplotlib can be installed by executing pip3 at the end of this process.

$ sudo /usr/local/bin/pip3 install matplotlib

Install the package to run IPython Notebook

Introduced the following packages.

$ sudo /usr/local/bin/pip3 install ipython jinja2 tornado pyzmq

end

After that, I ran IPython Notebook Server and put in pytest / Theano / wabbit_wappa, but it became difficult to put together, so it ends here. For IPython Notebook Server, the following sites are well organized for your reference. http://akiniwa.hatenablog.jp/entry/2013/11/25/001805

Enjoy PyData!

Recommended Posts

Summary from building Python 3.4. * From source to building a scientific computing environment
From building a Python environment for inexperienced people to Hello world
From installing Ansible to building a Python environment in Vagrant's virtual environment
Everything from building a Python environment to running it on Windows
Building a Python virtual environment
Building a Python virtual environment
Building a Python environment on Mac
Building a Python environment on Ubuntu
Building a virtual environment with Python 3
[Python] Building a virtual python environment for the pyramid tutorial (summary)
[Pyenv] Building a python environment with ubuntu 16.04
Building a Python3 environment with Amazon Linux2
Send a message from Python to Slack
Building a Python 3.6 environment with Windows + PowerShell
I want to build a Python environment
[Mac] Building a virtual environment for Python
Building a Python development environment for AI development
Add a Python virtual environment to VSCode
Building a Python development environment on Windows -From installing Anaconda to linking Atom and Jupyter Notebook-
Building a virtual environment for Mayavi dedicated to Python 3.6, Anaconda, Spyder users
Migration from Python2 to Python3 (Python2 is rebuilt as a virtual environment and coexists)
Edit Excel from Python to create a PivotTable
How to open a web browser from python
Building a python environment with virtualenv and direnv
Building a Python environment with WLS2 + Anaconda + PyCharm
How to generate a Python object from JSON
[Python] Web development preparation (building a virtual environment)
Think about building a Python 3 environment in a Mac environment
Introduction to Python "Re" 1 Building an execution environment
Building a Python environment on a Sakura VPS server
From Python environment construction to virtual environment construction with anaconda
Notes from installing Homebrew to building an Anaconda environment for Python with pyenv
Changes from Python 3.0 to Python 3.5
Changes from Python 2 to Python 3.0
Install python from source
Create a Python environment
From setting up Raspberry Pi to installing Python environment
Building a Python environment for pyenv, pyenv-virtualenv, Anaconda (Miniconda)
Write about building a Python environment for writing Qiita Qiita
How to set up a Python environment using pyenv
Recommendation of building a portable Python environment with conda
Building a Docker working environment for R and Python
Machine learning python code summary (updated from time to time)
How to build a Django (python) environment on docker
Steps from installing Python 3 to creating a Django app
From buying a computer to running a program with python
Building and enabling a python virtual environment, etc. (venv)
Procedure for building a CDK environment on Windows (Python)
Python development environment construction 2020 [From Python installation to poetry introduction]
Consider a conversion from a Python recursive function to a non-recursive function
Procedure to exe python file from Ubunts environment construction
conda memorandum: Building a Python environment with supercomputer ITO
Python script to create a JSON file from a CSV file
Building a Python environment for programming beginners (Mac OS)
Memo for building a machine learning environment using Python
How to build a Python environment on amazon linux 2
[Python] How to call a c function from python (ctypes)
How to create a kubernetes pod from python code
[It's not too late to learn Python from 2020] Part 2 Let's create a Python development environment
Post from Python to Slack
Run the program without building a Python environment! !! (How to get started with Google Colaboratory)