Install python on linux fedora

zobayer1 / fedora_install_python3.md

Python 3.9 comes as a default with Fedora 34. However, sometimes you may wish to install older versions for development and test purposes. Apart from groupinstall command, these instructions work for CentOS and REHL systems as well.

Install python development dependencies.

sudo dnf groupinstall "Development Tools" sudo dnf install python3-devel openssl-devel zlib-devel bzip2-devel sqlite-devel libffi-devel 

Note: You will need to rebuild and reinstall if you install new source or development libraries for python. Do not create or modify symlinks for python , python3 , etc, as that may and will break many dependent libraries in your system.

Visit https://www.python.org/ftp/python/ for latest releases for version 3.8.X and download the .tgz file. We will install Python-3.8.11 .

# download and extract source archive wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz tar xzf Python-3.8.11.tgz Python-3.8.11/ cd Python-3.8.11/ # configure with all optimizations ./configure --enable-optimizations --with-ensurepip=install # do not touch system default python sudo make altinstall # cleanup cd .. && sudo rm -rf Python-3.8.11/ 

You can remove the .tgz file, or keep it for future re-installation.

Visit https://www.python.org/ftp/python/ for latest releases for version 3.7.X and download the .tgz file. We will install Python-3.7.10 .

# download and extract source archive wget https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz tar xzf Python-3.7.10.tgz Python-3.7.10/ cd Python-3.7.10/ # configure with all optimizations ./configure --enable-optimizations --with-ensurepip=install # do not touch system default python sudo make altinstall # cleanup cd .. && sudo rm -rf Python-3.7.10/ 

You can remove the .tgz file, or keep it for future re-installation.

Due to some changes in memory allocation architecture, installation of ensurepip usually fails with gcc 11. An older gcc or clang is required. Install clang dependencies:

sudo dnf install clang llvm-devel 

Visit https://www.python.org/ftp/python/ for latest releases for version 3.6.X and download the .tgz file. We will install Python-3.6.13 .

# download and extract source archive wget https://www.python.org/ftp/python/3.6.13/Python-3.6.13.tgz tar xzf Python-3.6.13.tgz Python-3.6.13/ cd Python-3.6.13/ # configure with all optimizations CC=clang LLVM_PROFDATA=/usr/bin/llvm-profdata ./configure --enable-optimizations --with-ensurepip=install # do not touch system default python CC=clang sudo make altinstall # cleanup cd .. && sudo rm -rf Python-3.6.13/ 

You can remove the .tgz file, or keep it for future reinstallations.

Other versions of Python 3

Follow similar process as above.

Источник

How to Install Python on Fedora 38/37/36 Linux

LinuxCapable

Python is a high-level, interpreted programming language that has gained immense popularity over the years due to its simplicity, readability, and versatility. Created by Guido van Rossum in 1989 and first released in 1991, Python has evolved into a powerful language widely used for various applications, from web development and data analysis to artificial intelligence and machine learning. In this introduction, we will explore the key aspects of Python programming that make it stand out among other languages.

Читайте также:  Do you have linux downloader

Key Features and Benefits of Python Programming:

  • Readability: Python’s syntax is designed to be clean and easily readable, making it an excellent choice for both beginner and experienced programmers. The use of indentation to define code blocks and a focus on simplicity contribute to the language’s readability and maintainability.
  • Versatility: Python is a general-purpose programming language, which means it can be used for a wide range of applications. Its extensive standard library and numerous third-party packages make it suitable for web development, scientific computing, data analysis, automation, and much more.
  • Cross-platform Compatibility: Python runs on various platforms, including Windows, macOS, and Linux. This cross-platform compatibility makes it a valuable tool for developing applications that need to work seamlessly across different operating systems.
  • Strong Community Support: Python has a vast and active community of users, contributors, and developers who continuously work to improve the language and its ecosystem. This strong community support means that you’ll find a wealth of resources, tutorials, and libraries to help you with your Python projects.
  • Language Interoperability: Python can easily integrate with other programming languages, such as C, C++, and Java, allowing developers to utilize the best features of multiple languages in their projects.
  • Wide Adoption in Industry: Python’s flexibility and ease of use have made it a popular choice for many industries, including finance, healthcare, and technology. Its widespread adoption means that learning Python can open doors to a variety of career opportunities.

Whether you are just starting your programming journey or are an experienced developer looking to add a new language to your skillset, Python is a fantastic choice. With its intuitive syntax, extensive capabilities, and supportive community, Python offers a rewarding and engaging programming experience. The following guide will demonstrate how to install Python on Fedora Linux using Fedora’s repository.

Update Fedora

It is important to update your system regularly to ensure that your Fedora operating system is equipped with the latest versions of all packages. This can be achieved through a simple command entered in the terminal:

Method 1: Install Python with Fedora

Installing Python on Fedora is straightforward, given its focus on upstream releases. To install Python run the following command:

Python is a universal programming language, and many optional packages can be installed to take advantage of its full range of capabilities. Below is a list of some of the most popular optional Python packages that can be installed on Fedora Linux using the following command format:

Pip: a package installer for Python

sudo dnf install python3-pip

Python3-devel: development headers and libraries for Python 3

sudo dnf install python3-devel

Python3-venv: a tool for creating virtual environments for Python 3

sudo dnf install python3-vituralenv

NumPy: a library for working with arrays of numerical data

sudo dnf install python-numpy

SciPy: a library for scientific computing and advanced mathematics

sudo dnf install python-scipy

Matplotlib: a library for data visualization

sudo dnf install python-matplotlib

Pandas: a library for data analysis and manipulation

sudo dnf install python-pandas

Scikit-learn: a library for machine learning and data mining

sudo dnf install python-scikit-learn

Flask: a web application framework for Python

sudo dnf install python-flask

Django: a high-level web framework for Python

sudo dnf install python-django

Requests: a library for making HTTP requests

sudo dnf install python-requests

By installing these optional packages, you can expand the capabilities of your Python environment and enable a wide range of functionality. Whether you are working on data analysis, web development, or machine learning projects, installing these packages can help you achieve your goals more efficiently and effectively.

Читайте также:  Astra linux hp m1132 mfp

Verify the installation by checking the build.

Method 2: Install Python with Source

If you’re looking for a more advanced installation method for Python or need to install a specific advanced build from the Git repository of the source, you can choose to install Python directly from the source. However, it’s worth noting that this method can be more challenging and time-consuming than installing Python through a package manager. One of the main issues is that you won’t be able to update Python as easily as with a package manager, and you’ll need to recompile for any changes.

To install Python from the source on Fedora Linux, you’ll need to follow a few steps. First, you’ll need to install the necessary dependencies to build Python, including gcc, openssl-devel, bzip2-devel, libffi-devel, zlib-devel, wget, and make. You can do this by running the following command in the terminal:

sudo dnf install gcc openssl-devel bzip2-devel libffi-devel zlib-devel wget make 

Once you have installed the dependencies, you can visit the Python downloads page on the official website and download the latest version of Python. For example, you can use the wget command to download the Python 3.11.2 source file by running the following command:

wget https://www.python.org/ftp/python/3.11.2/Python-3.11.2.tar.xz

Once you have downloaded the file, you can extract the archive by running the following command:

You’ll then need to navigate to the source directory by running the following command:

Next, you’ll need to run the configuration script, which checks that all the necessary dependencies are present before the installation can proceed. You can run the configuration script with the following command:

./configure --enable-optimizations

It’s recommended to use the –enable-optimizations flag to optimize the Python binary by running multiple tests, although it will take extra time to complete.

After running the configuration script, you can start the build process with the make command. You can use the -j flag to specify the number of cores in your system to speed up the build time. For example, if you have two cores, you can run the following command:

Once the build process is complete, you can install Python by running the following command:

The altinstall command is used instead of the default install command to prevent overwriting the default python3 binary file /usr/bin/python.

Читайте также:  Linux hosts несколько ip адресов

Finally, you can check the version of the installation to ensure that it has been installed successfully and that its current build number is correct by running the following command:

Test Python: Create a Test Virtual Environment

After installing Python on your Fedora Linux system, it’s a good idea to test that it’s working correctly. A convenient way to do this is by creating a test virtual environment. A virtual environment is an isolated environment where you can test Python and its modules without affecting the global Python environment.

To create a test virtual environment, you’ll first need to install the python3-virtualenv package, including the venv module you can use to create virtual environments. You can install it by running the following command:

sudo dnf install python3-virtualenv

Once you have installed the package, you can create a new virtual environment in a directory of your choice. For example, you can create a virtual environment called myenv by running the following command:

This will create a new directory called myenv that contains the virtual environment. You can activate the virtual environment by running the activate script located in the bin directory of the virtual environment. You can activate the virtual environment by running the following command:

Once you have activated the virtual environment, you can test Python by running the following command:

This will display the version of Python that you’re running in the virtual environment. You can also install any Python modules that you want to test in the virtual environment using pip. For example, you can install the NumPy package by running the following command:

This will install the NumPy package in the virtual environment. You can test that the package is installed correctly by importing it into a Python script and running it. For example, you can create a new file called test_numpy.py with the following code:

import numpy as np arr = np.array([1, 2, 3]) print(arr)

Save the file and run it by running the following command:

This should output the following result:

By creating a test virtual environment and testing Python and its modules in isolation, you can ensure that everything is working correctly and avoid potential issues with the global Python environment. Once you’re done testing, you can deactivate the virtual environment by running the following command:

This will return you to the global Python environment.

Conclusion: Installing Python on Fedora Linux

In conclusion, Python is a versatile programming language that has become increasingly popular recently. It’s widely used in various applications, from web development to scientific computing and machine learning. If you’re using Fedora Linux, you have several options for installing Python, including using the default version from the Fedora repository, installing optional packages and essential components, or installing directly from the source. This should be enough to get you started with Python.

Источник

Оцените статью
Adblock
detector