Ubuntu 14.04 source code compile and install Python3.6 (reserve 3.4 pre-installed in the system)

Ubuntu 14.04 source code compile and install Python3.6 (reserve 3.4 pre-installed in the system)

# Switch root
sudo su-

# Download the source
cd / tmp
wget https://www.python.org/ftp/python/3.6.10/Python-3.6.10.tgz

# 安装编译环境,https://realpython.com/installing-python/#compiling-python-from-source
sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev \
                libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev  \
                libncursesw5-dev xz-utils tk-dev

# 防止Make 时出错double free or corruption (!prev)
# https://github.com/tensorflow/tensorflow/issues/8717
sudo apt-get -y install google-perftools
export LD_PRELOAD="/usr/lib/libtcmalloc.so.4" 

# Pre-configuration, optional for optimization,
tar -xf Python-3.6.10.tgz
cd Python-3.6.10
./configure --prefix = / usr / local / python3 --enable-optimizations

# Compile source code
make && echo OOKK

# In addition, the entire source package can be packaged after make is compiled
# Packaging command
cd / tmp && tar -cf py36maked.tar Python-3.6.10 && gzip py36maked.tar
# Installed on the same configuration machine, suitable for multiple machines in the cloud Same server

# On any server with the same configuration
sudo -s # Switch to root and stay in the current folder
rm -rf Python-3.6.0 # Delete the old source folder
rm -rf / usr / local / python3 / # Delete Old binary file
# Unzip and install
tar xf py36maked.tar.gz
cd Python-3.6.10
make install && echo OOOKKK # Install 3.6 version
exit # Exit root user

# Soft connect pip3 and python3.6, -f force to create it to overwrite
sudo ln -sf /usr/local/python3/bin/python3.6 /usr/bin/python3.6
sudo ln -sf / usr / local / python3 / bin / pip3 / usr / bin / pip3
sudo ln -sf / usr / bin / pip3 / usr / bin / pip

# Multiple versions of coexistence
# The original / usr / bin / python3 is /usr/bin/python3.4 Don't move it
sudo update-alternatives --config python3 # See what versions are currently available
sudo update-alternatives --remove python3 / usr /bin/python3.6 # Remove the extra 3.6 version
sudo update-alternatives --install / usr / bin / python3 python3 /usr/bin/python3.4 1 # The larger the final number, the higher the priority is
sudo update-alternatives --install / usr / bin / python3 python3 /usr/bin/python3.6 2
sudo update-alternatives --auto python3 # Set to auto mode
# In auto mode update-alternatives will choose the one with the highest priority value, here is 3.6

# Give the current user permission to operate / usr / local / python3 / in order to pip install the library file
sudo chown -R `id -u`:` id -g` / usr / local / python3 /


#Resolved version conflict # subprocess.CalledProcessError: Command '(' lsb_release ',' -a ')' during pip install
# Method 1: Find out where lsb_release.py is hiding, https://www.jianshu.com/ p / 3a2877edebe8
find / -name lsb_release.py
/usr/lib/python3/dist-packages/lsb_release.py
/usr/lib/python2.7/dist-packages/lsb_release.py
# Copy lsb_release.py to python3.6 Library directory
sudo cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python3/lib/python3.6/
# lsb_release 
# Display No LSB modules are available. It means normal.

# Method two: Not recommended, do not know what sequelae, https://github.com/pypa/pip/issues/4924
sudo mv / usr / bin / lsb_release /usr/bin/lsb_release.bak


# Test pip3 install software
pip3 install virtualenv --user
# --user table with current user permissions, no need
# Because the current user already has permission to operate / usr / local / python3 /
# Third-party library files are mainly installed in / usr / local / python3 / lib / python3.6 / site-packages

# Upgrade pip
pip3 install --upgrade pip

 

 

Published 27 original articles · praised 4 · visits 9691

Guess you like

Origin blog.csdn.net/yoshubom/article/details/104352748
Recommended