程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Jenkins - shell script installation upgrade Python 3

編輯:Python

introduction

Jenkins Realization CI/CD, To run Pyhon Script , And some of them VM By default, only Python 2, But the script must use Python 3 Environment . Or the system comes with Python 2 and Python 3 edition , But it needs to be updated Python 3. Of course, if you can find it easily DevOps The engineer , This problem is solved very well , Directly in VM Module mounting Python 3 Can then , But there are also people who cannot be contacted DevOps, Only forced Script Installation , Each run Python Before the script , Let's start with random assignment VM Put it on again Python 3. I am the latter , Not directly log in To VM operation , Only through the command belongs to the blind man and elephant exploration , Record some of the pits you've experienced .

Summary :

  1. understand Python Environmental Science
  2. New installation Python 3
  3. upgrade Python

understand Python Environmental Science

You can pass some orders , Let's see Python Environment .

View the installed in the current environment Python

perform whereis python command

console output:
More fortunate , There are many versions of this machine Python.

see Python Corresponding soft link

perform ls -l /usr/bin|grep python Before the command first looks Python Corresponding to soft link

console output:
Python 3 The corresponding is Python 3.8 edition
Python 2 The corresponding is Python 2.7 edition
Python The corresponding is Python 3

You can further verify the version : Execute the following command
python -V
python2 -V
python3 -V


console output:

New installation Python 3

Learn from some commands Python Environmental conditions , But if something bad happens , The environment is not equipped with any Python 3 edition , Then you have to install a new set Python 3 Environmental Science .

Know the system version

By executing orders cat /proc/version
console output:
Learned yes Ubuntu System , Different systems can also have an impact .

And down here we are Ubuntu System to install new Python 3 Environmental Science

  1. Install compilation dependencies
    sudo apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev
    If this is not done, some problems may arise , such as :
    handle ModuleNotFoundError: No module named '_bz2'
    Command 'lsb_release -a' returned non-zero exit status 1
  2. Download and unzip the source code package
    wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tar.xz
    tar -xvJf Python-3.11.0.tar.xz
  3. Compilation and installation
    cd Python-3.11.0/
    sudo ./configure prefix=/usr/local/py3 CFLAGS=-fPIC
    sudo make && make install
  4. Modify soft links
    sudo ln -sf /usr/local/py3/bin/python3.11 /usr/bin/python3
    sudo ln -sf /usr/local/py3/bin/pip3.11 /usr/bin/pip3
  5. Test success
    python3 -V
    pip3 -V or python3 -m pip -V

complete Shell Script :

cd /usr/local
if [ ! -d "/usr/local/py3" ]; then
sudo mkdir /usr/local/py3
fi
sudo chmod -R 777 /usr/local/py3
cd /tmp
sudo apt-get install -y zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev
wget https://www.python.org/ftp/python/3.11.0/Python-3.11.0.tar.xz
tar -xvJf Python-3.11.0.tar.xz
cd Python-3.11.0/
sudo ./configure prefix=/usr/local/py3 CFLAGS=-fPIC
sudo make && make install
sudo ln -sf /usr/local/py3/bin/python3.11 /usr/bin/python3
sudo ln -sf /usr/local/py3/bin/pip3.11 /usr/bin/pip3
python3 -V
pip3 -V

upgrade Python

Most of Linux Distribution version (Ubuntu、CentOS etc. ) It's all brought by default Python. yes , we have Linux The distribution even comes with two versions Python, For example, the latest version of Ubuntu Will bring it Python 2.x and Python 3.x. What do you think is existing Python 3 The version is not new enough , Then we need to update Python edition .

stay Ubuntu The terminal can be updated by executing the following two commands Python edition :
sudo apt-get update
sudo apt-get install python3.11

The first command specifies the update /etc/apt/sources.list and /etc/apt/sources.list.d The source address listed , This ensures that you get the latest installation package .

The second command specifies the installation Python 3.11, This is the latest Python edition .


Console Output:
Compared with the previous one, there is no upgrade , More than a python3.11 了 , If you need to use this version , Refer to the above to change the soft link .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved