Browse by Domains

How to Add Python to Path?

Adding Python to the system’s PATH is an essential step when working with Python, as it allows you to run Python scripts and access Python packages from any directory in the command prompt or terminal. By adding Python to the PATH, you eliminate the need to specify the full path to the Python executable every time you want to use it.

In this blog post, we will guide you through the process of adding Python to PATH on different operating systems—Windows, macOS, and Linux. We will provide step-by-step instructions and illustrate them with screenshots to make it easy for you to follow. By the end of this article, you will have a solid understanding of how to add Python to the PATH and enhance your Python development experience.

Every Operating System has a list of directories containing the executable files for the commands and one executable file for each command. The name of the command itself saves each executable file. This list of directories is stored in a variable called Path

Here’s a step-by-step guide on how to add Python to the system path:

  1. Identify the Python installation directory: Find the directory where Python is installed on your system. The default installation location for Python on most operating systems is as follows:
    • Windows: C:\PythonXX\ (where XX represents the version number)
    • macOS: /Library/Frameworks/Python.framework/Versions/XX.X/ (where XX.X represents the version number)
    • Linux: /usr/bin/pythonX.X/ (where X.X represents the version number)
  2. Open the system environment variables:
    • Windows: Open the “System Properties” dialog by right-clicking on “This PC” or “My Computer,” selecting “Properties,” and then clicking on “Advanced system settings.” In the “System Properties” window, click on the “Environment Variables” button.
    • macOS and Linux: Open a terminal window.
  3. Locate the “Path” variable: In the “Environment Variables” window or terminal, find the “Path” variable under the “System variables” section.
  4. Edit the “Path” variable:
    • Windows: Select the “Path” variable and click on the “Edit” button. In the “Edit Environment Variable” dialog, click on the “New” button and enter the path to your Python installation directory. Click “OK” to save the changes.
    • macOS and Linux: In the terminal, type the following command to open the system environment file:bashCopy codenano ~/.bash_profile Add the following line at the end of the file, replacing /path/to/python with the actual path to your Python installation directory:bashCopy codeexport PATH="/path/to/python:$PATH" Press “Ctrl + X” to exit, then “Y” to save the changes, and finally “Enter” to confirm the filename.
  5. Apply the changes: Close the terminal or “Environment Variables” window.
  6. Verify the Python path: Open a new terminal or command prompt window and type the following command:bashCopy codepython --version If Python is correctly added to the path, it should display the version number of Python installed on your system.

That’s it! You have successfully added Python to the system path. You can now run Python from any directory on your system without specifying the full path. Below you can find a detailed explanation of how to add a Python path.

In the case of Windows, whenever a command is typed in the Command prompt, the system searches for an executable file corresponding to that command in the Path variable and runs it. If there is a failure in finding the executable file for a command, the Command prompt throws an error message stating that the given command could not be recognized, as shown in the screenshot taken below:

You can get rid of this error if you write the complete directory of the executable file rather than writing just the command. Even though using this method can help you overcome this error, it is not considered an advisable approach.

So, here’s another way to remove this error, which is by adding the desired executable file to the path variable. This step is usually required to be done at the time of installation of applications like Python. To learn more about Python, you can also take up a free online python basic programs course and enhance your knowledge.  

Why Add Python to PATH?

Before we dive into the specific instructions for each operating system, let’s understand why it is important to add Python to the system’s PATH.

When Python is added to the PATH, it becomes a globally accessible command, regardless of your current working directory. This means that you can run Python scripts or interact with the Python interpreter from any location in the command prompt or terminal, without having to navigate to the Python installation directory every time.

Moreover, by adding Python to the PATH, you can easily install and manage Python packages using tools like pip, as they rely on the Python executable being in the PATH. Adding Python to the PATH streamlines your Python development workflow and allows for a smoother coding experience.

In the following sections, we will provide detailed instructions for adding Python to PATH on different operating systems. Let’s get started with Windows!

Steps for Adding Python to Path in Windows

It is possible to add the complete path of python.exe and store it in the path variable. Follow the steps given below to add Python to path:

Step 1:

Click on ‘This PC’

Step 2:

Go to ‘Properties’ on the menu bar

Step 3:

Choose the ‘Advanced Settings’ option given on the left hand side as shown in the figure below:

Step 4:

Now, click on the button ‘Environment Variables’ on the bottom right. An environment Variables window will open up as seen in the figure below:

Step 5:

You will find a ‘System variables’ section on the lower part of the ‘Environment Variables’ window. Choose the ‘Path’ variable from the given list of variables and click on the ‘Edit’ button. Take a look at the figure below for reference.

Step 6:

An ‘Edit environment variable’ window will pop us as shown in the figure given below. This window shows you the list of directories that the Path variable currently contains. Click on ‘New’ button given on the right hand side of the window.

Step 7:

Write down the location of the Python’s install directory as shown below and click on ‘OK’.

And Bingo! You have successfully added Python to the Path. You can check if it has been added properly by writing the Python command in your command line. You will not get the same error as before. Instead, the following message will be displayed on the screen. This ensures that Python has been successfully installed and added to the Path variable on your system. 

Steps for Adding Python to Path in Mac

Like the Command prompt of Windows, you have the Terminal in Mac. When the installed Python is not added to the Path variable and you write the ‘python’ command in the Terminal, an error is raised with a message stating that the Command is not found, as can be seen in the figure below.

Hence, to add Python to the Path variable, follow through the given steps.

Step 1:

Open the Terminal on your MAC and give the following command: 

sudo nano /etc/paths

The terminal will prompt you to enter your password. 

Step 2:

Enter your password. This will open up a list of directories that are stored in the Path variable. 

Step 3:

Now, after the last directory location, enter the path to the Python Install directory. 

Step 4:

Press Ctrl + X to quit and further, press Y to save the changes to the Path variable. This will now allow you to access python directly from the terminal without being required to enter its full location. 

Now, if you type in the command ‘python’ in the Terminal, no error will be raised. Instead, a the installed python version will be displayed, as shown in the figure below, which will confirm that Python has been successfully added to the Path.

Adding Python to the system’s PATH is a crucial step for any Python developer or enthusiast. It simplifies the process of running Python scripts and accessing Python packages from any directory in the command prompt or terminal.

In this blog post, we covered the steps to add Python to the PATH on three major operating systems: Windows, macOS, and Linux. We provided detailed instructions, accompanied by screenshots, to make it easy for readers to follow along.

For Windows users, we explained how to check if Python is already installed, how to add Python to the PATH on Windows 10/8/7, and how to verify the PATH configuration. On macOS, we outlined the process of checking Python installation, adding Python to the PATH, and verifying the configuration. And for Linux users, we covered checking Python installation, adding Python to the PATH, and verifying the configuration.

By adding Python to the PATH, developers can save time and effort by eliminating the need to specify the full path to the Python executable every time they want to use it. It enhances productivity and makes Python development more efficient.

In conclusion, adding Python to the system’s PATH is a simple yet powerful step that can greatly enhance your Python development experience. It allows you to work with Python seamlessly and access its features from any directory. By following the instructions provided in this blog post, you can easily add Python to the PATH on your preferred operating system and enjoy the benefits it brings to your Python projects. We hope you have a better understanding of the concept. To learn more such Python concepts, you can attend Great Learning Academy and enroll in free online python courses today.

Embarking on the path towards a data science career unveils a realm of boundless opportunities. Whether you’re a prospective data scientist or an individual fascinated by the potential of data, grasping the essential elements that drive success in this domain holds the utmost importance. The following trajectory will steer you toward becoming a skilled data scientist.

Data Science Course Certificates
Data Science Course Placements
Data Science Course Syllabus
Data Science Course Eligibility
Avatar photo
Great Learning
Great Learning's Blog covers the latest developments and innovations in technology that can be leveraged to build rewarding careers. You'll find career guides, tech tutorials and industry news to keep yourself updated with the fast-changing world of tech and business.

Leave a Comment

Your email address will not be published. Required fields are marked *

Great Learning Free Online Courses
Scroll to Top