Python is a versatile, powerful, and easy-to-learn programming language that has become popular worldwide. Installing Python on your openSUSE system is essential for many applications, including web development, data analysis, and automation. In this tutorial, we will show you how to install Python on openSUSE step by step, whether you prefer to use the default package manager or compile it from the source.
How to Install Python on openSUSE
Table of Contents
- Installing Python using Zypper
- Compiling Python from source
- Setting up a Python virtual environment
Before installing Python on openSUSE, ensure your system is up to date:
sudo zypper update
Installing Python using Zypper
The simplest method of installing Python on openSUSE is using the default package manager, Zypper. By default, openSUSE comes with Python 3 pre-installed. You can check the Python version by running:
To install Python 2, execute the following command:
sudo zypper install python2
Now you have Python 2 and Python 3 installed on your openSUSE system. You can switch between them by using the
Note: Python 2 has reached its end of life, and it’s recommended to use Python 3 for new projects.
Compiling Python from the source
If you want to install a specific version of Python, you can compile it from the source. To do this, follow these steps:
- Install the required dependencies:
sudo zypper install gcc make openssl-devel zlib-devel libffi-devel readline-devel sqlite3-devel
Download the desired Python version from the official Python website:
3.9.7 with your desired version.
Extract the downloaded archive:
tar -xf Python-3.9.7.tar.xz
Change to the extracted directory:
Configure the Python installation:
Compile and install Python:
make sudo make altinstall
altinstall prevents the new Python version from replacing the system Python.
Verify the new Python version:
3.9with your installed version.
Setting up a Python virtual environment
A Python virtual environment allows you to isolate project-specific dependencies and avoid conflicts with system packages. To set up a virtual environment, follow these steps:
- Install the
sudo zypper install python3-virtualenv
Create a new directory for your project:
mkdir my_project cd my_project
Create a virtual environment:
python3 -m venv venv
Activate the virtual environment:
Now you can install Python packages specific to your project without affecting the system packages
- Install project-specific Python packages:
pip install package_name
package_name with the desired Python package. You can also use a
requirements.txt file to install multiple packages at once:
pip install -r requirements.txt
Deactivate the virtual environment when you’re done working on your project:
To keep your Python installation up-to-date, follow these steps:
- Update your system packages:
sudo zypper update
Upgrade the Python package:
sudo zypper upgrade python3
python2 if you want to upgrade Python 2.
Note: If you compiled Python from the source, you need to repeat the compilation steps with the updated source code.
You’ve now learned how to install Python on openSUSE using both the package manager and by compiling from source. You also know how to create a Python virtual environment to isolate your project dependencies. With Python installed, you can now explore various applications and projects, like web development with Django, data analysis with pandas, or even machine learning with TensorFlow.