[LINUX] Install Python locally

Note that I got stuck when installing Python locally. It is assumed that you do not have administrator privileges (when sudo cannot be used). I installed Python3.6.1, but I think it can be applied to other versions.

environment

Download and extract to \ $ HOME / src, and proceed with the discussion assuming that it will be installed in \ $ HOME / local.

Install tcl / tk

First, since tkinter is required for matplotlib, install tck / tk in advance. If you already have it installed and you know the installed lib and include directories, you can skip it. In my case, I didn't know the installation directory (and the version was old), so I installed it locally.

The latest version of tcl / tk is 8.6.6, so install it. Download from the link in Official Site.

First, install tcl.

cd $HOME/src
wget https://sourceforge.net/projects/tcl/files/tcl8.6.6-src.tar.gz/download -O tcl8.6.6.tar.gz
tar xzvf tcl8.6.6.tar.gz
cd tcl8.6.6
mkdir build; cd build
../unix/configure --prefix=$HOME/local/
make
make install

Install tk in the same way.

cd $HOME/src
wget https://sourceforge.net/projects/tcl/files/tk8.6.6-src.tar.gz/download -O tk8.6.6.tar.gz
tar xzvf tk8.6.6.tar.gz
cd tk8.6.6
mkdir build; cd build
../unix/configure --prefix=$HOME/local/
make
make install

Python installation

Next, install Python. Note that tkinter will not work if you install it without thinking about it.

The latest version of Python is 3.6.1, so install this. Download from the link in Official Site.

cd $HOME/src
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar xfv Python-3.6.1.tar.xz
cd Python-3.6.1
mkdir build; cd build
../configure --prefix=$HOME/local/ --with-tcltk-includes="-I/$HOME/local/include" \
   --with-tcltk-libs="-L/$HOME/local/lib -ltcl8.6 -ltk8.6"
make
make install

It should be noted that the include directory and lib directory are optionally specified when executing configure. Without it, it throws an error when running after Python is installed. As an error message

    import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'

You can get something like this.

Towards the end of the installation message

Python build finished successfully!
The necessary bits to build these optional modules were not found:
_gdbm                 _lzma
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

If you need these packages, you need to specify another option. If you are in trouble, you can refer to the setup.py script in the extracted Python directory.

If you install pip at the end, the installation is completed.

wget https://bootstrap.pypa.io/get-pip.py
$HOME/local/bin/python3 get-pip.py

You can try plt.show () etc. to check if it works.

Recommended Posts

Install Python locally
install python
Install NAOqi python
Install Python Control
CentOS8 --Install --Python3
Install python on WSL
How to install Python
Install Python on Pidora.
Install Scrapy on python3
Install Python on Mac
How to install python
Install python from source
Install Python3.4 on CentOS 6.6
Install Python Jupyter lab
Install python external library
Install python (pyenv, pyenv-virtualenv)
Install Voluptuous with Python 2.5
Install python on windows
Python PyTorch install tips
Install Python 2.7.3 on CentOS 5.4
Install python with pyenv
Install Python 3.3 on Ubuntu 12.04
Install Python 3.4 on Mac
Install Python 3.6 on Docker
Install Python (for Windows)
[Procedure memo] Install Python3 + OpenSSL locally on Ubuntu
[2020.8 latest] How to install Python
Install Python 3.8 on RHEL 8 (AppStream)
Install watchdog on Windows + Python 3.3
Install Python and Flask (Windows 10)
Install Python environment with Anaconda
Python
Install pygame on python3.4 on mac
Windows10: Install python dlib library
Install external libraries with Python
Install multiple versions of Python
Install pandas 0.14 on python3.4 [on Mac]
Install Python 3.7 and Django 3.0 (CentOS)
Install OpenCV on Ubuntu + python
Manipulate spreadsheets locally using Python
Python --Install MySQLDB on EC2
Install pyenv from Homebrew, install Python from pyenv
Install Python 3.8 on CentOS 8 (AppStream)
[Python] [Chainer] [Windows] Install Chainer on Windows
Python install in 2 lines @Windows
Install dlib for Python (Windows)
How to install python using anaconda
Install Python Pillow on Amazon Linux
Install Python 3.8 on Ubuntu 18.04 (OS standard)
Install Python 2.7.9 and Python 3.4.x with pip.
Install Cheminformatics Tool RDKit for Python
Install Python3 on Sakura server (FreeBSD)
HomeBrew can't install Python (at Mavericks)
Install Python from source with Ansible
Install python2.7 on windows 32bit environment
Install xgboost (python version) on Windows
pip install mysql-Error handling during python
Install scrapy in python anaconda environment
Install Pytorch on Blender 2.90 python on Windows
Install Python 3.7 Anaconda on MAC, but Python 2
[Linux] Install Python 3 without administrator privileges