Easy way to IT Job

How Do I Install Python Correctly
Share on your Social Media

How Do I Install Python Correctly?

Published On: April 5, 2024

How Do I Install Python Correctly?

Building dependable software for nearly any purpose is possible with Python’s ease of use, intuitiveness, and robustness. It can be challenging to set up and manage, though, as it is still merely software. In this article, we’ll cover the ins and outs of installing Python correctly, including which version to use, how to avoid conflicts between versions, and how to avoid any potentially dangerous situations.

A guide to choosing the right Python version and distribution

When choosing a Python version to ensure compatibility with third-party modules, it is always safer to go with one major point revision following the current one.

The most recent version of Python is 3.12 as of this writing. Therefore, it is safest to utilize Python 3.11’s most recent upgrade. Going back to one version ensures the best compatibility with popular third-party Python packages. Still, you may always test out the latest version of Python in a controlled manner, such as on a virtual machine or test computer.

Similar to Linux, Python is available in a multitude of distributions. However, unlike Linux, Python has a single, reliable, “official” edition that you can always rely on, CPython, made available at python.org by the Python Software Foundation. Once more, no one gets fired for using this distribution because it is the safest and most widely compatible.

Choosing between the 32-bit and 64-bit versions of Python is a crucial decision you’ll need to make, particularly on Windows. 64-bit is the most likely response for the following reasons:

  • The bulk of modern operating systems use 64-bit Python by default. Users of Windows can run 32-bit versions of Python on 64-bit Windows but with little performance impact. 
  • 32-bit applications and 32-bit Python programs can access a maximum of 4GB of RAM at once. Many Python data analysis and machine learning tools work better in 64-bit versions since this limit does not apply to 64-bit programs. Some are exclusive to 64-bit versions. 

If a third-party module you’re using is limited to 32-bit editions, or if you’re compelled to use a 32-bit version of Windows, then you should only choose the 32-bit version of Python. 

Proper Installation of Python

Python uses an installer that walks you through the setup process and installs on Windows just like any other application.

By default, the Python installer for Windows stores its executables under the user’s AppData directory, preventing the need for administrator access. Install Python in a higher-level directory if you are the only user of the machine to make it easier to discover. The target directory can be specified using the Windows installer.

Tips to choose the right Python installer for Windows

Python is available for Windows in several versions, according to Python.org. You have the option of using the embeddable zip file, the executable installer, or the web-based installer in addition to the 32-bit (“x86”) and 64-bit (“x86-64”) versions that were previously mentioned. This is the main idea behind those:

  • The Python setup is carried out via the executable installer, which is simply a ‘.exe’ file. The most popular and simple default option is this one.
  • Similar to the executable installer, the web-based installer downloads the necessary files individually to complete the installation. This needs a network connection, but it significantly minimizes the size of the installer itself.
  • With no dependencies and the ability to execute in a single folder, the embeddable zip file is a simple and self-contained version of the Python program. When you need a fast, one-time Python install to test something on the spot or when you want to manually distribute a Python application, a bundle can be helpful. Yet, pip and all the other helpful tools that come with a full install are not included in the embeddable zip, so it should only be used by experts.

Installing Python using Package Manager

Using one of the Windows package management solutions is still an additional choice. NuGet is a ‘.NET package management tool’ that has Python available in its repository. But the primary purpose of having Python available there is to use it as an element of a ‘.NET program’, not to set up a stand-alone instance of Python for everyday usage. Installing the standard Python method should make managing your Python instance easier. 

Python is also available through the more all-encompassing Windows package manager, Chocolatey. Chocolatey is a more practical option than NuGet for installing the Python language runtime and monitoring its presence on your system. On the same machine, it is advisable to refrain from combining conventional Python installations with Chocolatey installs.

Installing Python on Linux Correctly

Python is usually installed on Linux via the package manager of the particular distribution, as Linux distributions vary greatly from one another. For example, the installation process for Python varies greatly between Fedora and Ubuntu. Usually, the Python version number determines the destination location for the installation on Linux (and MacOS). 

Example: /usr/bin/python3.X on Linux, or /usr/local/opt/python/ on the Mac.

Using a Python runtime that is containerized is one method to get around the complexities of Linux package management. You can stop worrying about multiple Python runtimes stomping on each other’s toes because containers operate in isolation from the rest of the system. 

Note: If containers aren’t already a part of your process, you’ll have to invest time and effort in learning Docker. 

A useful tool in this context is also ‘asdf-vm’. Numerous Python runtimes, as well as numerous runtimes for Node.js, Ruby, Elixir, and many more languages, may be managed on Unix-like platforms (Linux and MacOS) with the help of asdf-vm. You should therefore explore asdf-vm if you frequently find yourself juggling versions of other programs in addition to Python.

Installing Python on MacOS Correctly

An older version of Python—Python 2.7—has never been included in the MacOS installation bundle. The two versions frequently clashed, which caused issues when Python 3 was released. 

The official Python manual offers a few statements to that effect, but the only more detailed advice is to make sure you use the correct path for the Python instance you want.

Using the Homebrew package manager on Mac OS is a popular method of managing Python runtimes. For obtaining, installing, managing, and uninstalling Python and other third-party command-line applications, Homebrew offers a standardized user interface.

Installing Python Packages Correctly

Even if you only want to use Python for one project, once you have a base install of a Python version set up, you should not begin installing packages straight into it using pip. After configuring your project directories, establish virtual environments for Python and install packages within them. In this manner, the base installation is kept tidy.

An overview of managing several projects with virtual environments and dependencies may be seen in the Poetry Project. Poetry provides a high-level command-line tool for controlling dependencies and virtual environments.

Install different versions of Python simultaneously

Managing several Python versions installed side by side is the single most difficult problem to solve when it comes to Python installations. Here, two general guidelines come into play:

  • Install every version in a distinct directory at all times.
  • Make sure that all system paths are set up to automatically start at the version you wish to run.

Per-project virtual environments are strongly supported by running various versions of Python. All Python activity within the project’s context is automatically routed toward the appropriate version of Python upon activation of the virtual environment. 

The ‘py’ launcher software gives Windows users another way to choose which Python version to use when multiples are installed. Installing the ‘py’ launcher, a tiny application that allows you to choose the version of Python to use for a particular script using command-line options, is an option that appears during the Python setup process. For example, py – 3.7 -m pip would be entered to execute pip for Python 3.7.

Upgrade Python Correctly

Python revision upgrades of minor versions, from 3.7.2 to 3.10, are usually not too difficult. When an installer finds the previous version on Windows, it updates it. The installer or package manager usually performs the same function on Linux and MacOS.

The virtual environments you have built, however, do not automatically upgrade; you will also need to upgrade them. Simply navigate to the virtual environment directory and type ‘venv –upgrade’ to upgrade Python in a virtual environment. Remember that this is only effective for small point revision upgrades, such as from Python 3.7.2 to Python 3.7.3.

Using venv to establish a new, distinct virtual environment subdirectory in the project directory, reinstalling any dependencies into it, and switching to using the new virtual environment is your best option if you’re undertaking a big point revision update, like upgrading Python 3.10 to 3.11. You can transition between several virtual environments in a project by using the majority of IDEs that support Python, including Microsoft Visual Studio Code.

How Do I Install Python Correctly?

Python can be installed on Windows in a few simple steps.

Step 1: Choose the Python version to install

There are multiple versions of Python available, and each version differs in terms of syntax and functionality. Selecting the version that we require or wish to use is necessary. For Python 2 and Python 3, there are various versions available.

Step 2: Download the Python Executable Installer

Navigate to the Download for Windows section on the Python official website (www.python.org) using your web browser.

There will be a list of every Python version that is available. After choosing the version you need, click “Download.” Assume for the moment that we selected Python 3.9.1.

A list of possible executable installers with varying operating system requirements will appear when you click “download.” Select the installer that corresponds with your operating system and start the installation process. Assuming we choose the Windows 64-bit installation, the download size is less than 30MB.

Step 3: Launch the Executable Installer

The Python 3.9.1 Windows 64-bit installation was downloaded.

Launch the installation. After confirming that the two checkboxes at the bottom are selected, click Install New.

Clicking the Install Now button starts the installation procedure.

It will take a few minutes to finish the installation process, and when it does, the following screen appears.

Step 4: Confirm that Python is installed correctly on Windows.

to verify whether Python has been installed on your system successfully. Take the prescribed actions:

  • Get the command prompt open.
  • Enter “python” after typing it.
  • If Python has been installed on your Windows computer successfully, the version of Python that you have installed will be shown.

Step 5: Confirm that Pip was set up.

Pip is a robust mechanism for managing Python software packages. Therefore, confirm that it is installed.

To confirm if the pip was installed, adhere to the instructions provided.

  • Get the command prompt open.
  • To find out if pip was installed, enter pip –V.
  • If the pip is installed successfully, the output is shown in the command line.

Python and pip have been successfully installed on our Windows computer.

Conclusion

Python is an emerging member of the programming language community that is strong and adaptable. Developers from a wide range of domains choose it because of its readability, simplicity, and vast ecosystem of libraries and frameworks. 

In this blog, we have taught how to install Python correctly on Windows, Linux, and MacOS. To learn with hands-on exposure, join our Python training institute in Chennai to launch your bright career with in-demand Python skills.

Share on your Social Media

Just a minute!

If you have any questions that you did not find answers for, our counsellors are here to answer them. You can get all your queries answered before deciding to join SLA and move your career forward.

We are excited to get started with you

Give us your information and we will arange for a free call (at your convenience) with one of our counsellors. You can get all your queries answered before deciding to join SLA and move your career forward.