Intranet environment build Python3 environment and install third-party libraries (Linux)

 

1. Python 3.6 build

1.1 Download Python 3.6

Go to the Python official website to download the corresponding Linux version Python (Python-3.6.8.tgz)

1.2 Unzip the compressed package

Put the downloaded Python-3.6.8.tgz into a path through tools such as ftp, such as /root/gf0719

Enter the directory: cd /root/gf0709

Unzip the file: tar xf Python-3.6.8.tgz

Enter this folder to prepare for configuration: cd Python-3.6.8.tgz

1.3 Configuration

./configure

1.4 Compile

sudo make

1.5 Installation

sudo make install, at this point, the installation of Python 3.6.8 is complete

2 Modify the default Python version

Generally, Linux systems will come with Python2, such as CenterOS, etc. By entering python directly in the terminal, Python2 will be called by default, so some modifications need to be made to change the default call Python3.

First delete the default call python2 points:

cd /usr/bin

sudo rm –rf python

Then enter the default installation path of Python3: cd /usr/local/bin

Display all files containing python: ls -l|grep python

Set the point of python to python3: sudo ln -s /usr/local/bin/python3 /usr/local/bin/python

Check whether it points to success: ls -l|grep python

The setting is successful, enter python to see if Python 3.6.8 is called

Set up successfully!

3. Install Python third-party libraries in the intranet environment

Installation conditions: 1. Linux system/virtual machine (CenterOS or Ubuntu) that can connect to the external network

          2. The Linux system has a Python environment installed

Step 1 : Download the required third-party libraries (such as pymysql) from the external network Linux, and execute the following commands in the terminal

              pip download pymysql -d gf/pymysql -d followed by the third-party library file storage path, such as gf/numpy

As shown in the figure above, the download is successful.

Find the corresponding directory and view the downloaded file:

Note: Sometimes the installation of third-party libraries will have dependent packages, that is, more than one installation file will be downloaded. (If there is a dependent package, install the dependent package in the second step of installation, and then install the main package, such as the pymysql downloaded above )

 

Step 2 : Put the downloaded third-party library files into the corresponding directory through ftp and other tools, such as: /root/gf0719/data/pip_source/pymysql

Enter the corresponding file directory: cd /root/gf0719/data/pip_source/ pymysql

Execute the installation command: pip install PyMySQL-0.9.3-py2.py3-none-any.whl

As shown in the figure above, the installation is successful.

Note: Should the installation of third-party libraries are mistakes in the call, please folder _bz2.cpython-36m-x86_64-linux-gnu.so copy to Python3.6 of /usr/local/lib/python3.6/ Under lib-dynload , re-enter the python environment in the terminal .

This error is due to a dependency problem that occurs when using the official source release installation under Linux . You can manually put the missing files into the environment.

Attach download address: Link: https://pan.baidu.com/s/1oAtuxUfz-Im8Wox4iw7ETg Password: wn1i

Guess you like

Origin blog.csdn.net/gf19960103/article/details/96483511
Recommended