# Install Python 3.8 on SLE Micro 5.5 <style> .indent-title-1{ margin-left: 1em; } .indent-title-2{ margin-left: 2em; } .indent-title-3{ margin-left: 3em; } </style> 1. Login as root user ``` $ sudo -i ``` 2. Open up a transactional-update shell session ``` $ transactional-update shell ``` 3. install the necessary interdependent software packages ``` $ zypper install zlib-devel make gcc ``` 4. Download the python from `www.python.org` ``` $ curl -sO https://www.python.org/ftp/python/3.8.20/Python-3.8.20.tgz ``` 5. Unzip it and Go to the folder ``` $ tar zxfv Python-3.8.20.tgz && \ cd Python-3.8.20/ ``` 6. Make a directory where you want to put your python. I called my `.localpython3.8` (name it whatever you want) and make it under the home directory. Configured the Python make ``` $ mkdir /root/.localpython3.8 $ ./configure --prefix=/root/.localpython3.8 ``` 7. Make and make altinstall (see difference between install and altinstall here) ``` $ make $ make altinstall ``` 8. Exit the `transactional-update` session and reboot to the new snapshot that contains the changes you have made ```bash! $ exit $ reboot ``` 9. Login as root user again ``` $ sudo -i ``` 10. configure PATH env and alias ``` $ cat <<'EOF' >> /root/.bashrc export PATH=/root/.localpython3.8/bin:$PATH EOF $ cat <<'EOF' >> /root/.alias alias python=/root/.localpython3.8/bin/python3.8 EOF $ exit # Login again $ sudo -i ``` 11. 寫一個簡單的程式快速測試 ``` $ cat <<'EOF' > test.py message = "Hello, World!" print(message) numbers = [1, 2, 3, 4, 5] for num in numbers: print(num) def add_numbers(x, y): return x + y result = add_numbers(2, 3) print(result) import datetime now = datetime.datetime.now() formatted_date_time = now.strftime("%Y-%m-%d %H:%M:%S") print(formatted_date_time) EOF ``` 12. 執行測試程式 ``` $ python test.py ``` 執行結果如下 : ``` Hello, World! 1 2 3 4 5 5 2024-11-14 16:06:00 ``` ## 參考文章 - [Install Python on Linux without Sudo](https://justinhou95.github.io/blog/2024/install-python/)