Python is not recognized as an internal or external command, operable program or batch file jenkins

Article ID:230613127

1 minute readKnowledge base

The bat directive in Pipeline returns cmd is not recognized as an internal or external command, operable program or batch file.

  • You need to make sure the user running the Jenkins Master/Agent where the command is executing has C:\Windows\System32 in it’s PATH variable.

  • To add this to that user’s PATH, right click on My Computer then select Properties. Click Advanced then click Environment Variables. Scroll down to PATH and add C:\Windows\System32 to it.

  • If the PATH is properly set but the error still appears, include the PATH through a environment variable. This is a known bug managed in https://issues.jenkins.io/browse/JENKINS-44334.

    environment { env.PATH = env.PATH + ";c:\\Windows\\System32" }

Given the increasing popularity of Python, it’s understandable why a lot of users are trying to run Python commands from the Windows Command Prompt. But the problem with this is, if you don’t specify Python’s full path for each command in part, you’ll end up getting an error saying that “Python is not recognized as an internal or external command, operable program or batch file.“

Python is not recognized as an internal or external command, operable program or batch file jenkins
“Python is not recognized as an internal or external command, operable program or batch file.”

What is causing the Python is not recognized as an internal or external command error?

This particular error occurs because the user has not specified the full path of the Python distribution. In order for the command to be successful in the current state, the user would have needed to specify the full path of the Python distribution inside the command.

If you want to run Python commands without having to add Python’s full path with each command, you’ll need to add Python to the Windows Path manually. Doing this can be somewhat confusing if you haven’t done this before.

In an attempt to make things easier for you, we’ve created a step-by-step guide that will walk you through the process of adding the Python path to a Windows environment.

Adding a Python to the Windows PATH

In order for this procedure to be successful, you need to ensure that the Python distribution is correctly installed on your machine.

Update: The Windows installer of Python 3.3 (or above) includes an option that will automatically add python.exe to the system search path. Using this installation method will save you from performing the steps below. You can download the latest web installer version of Python from this link (here). You’ll then have to download and run the appropriate x86 or x64 Windows Executable installer, depending on your CPU architecture.

Python is not recognized as an internal or external command, operable program or batch file jenkins
Downloading the appropriate Python installation executable

If you already installed Python on your machine, the steps below will show you how to add Python to the Windows path. Doing this successfully will allow you to run Python commands from a Command Prompt window without having to specify Python’s full path with each command. The following procedure is compatible with Windows 7, Windows 8 (8.1) and Windows 10.

  1. Press Windows key + Pause key to open the System Properties menu. Alternatively, you can right-click on Computer (This PC) in the Start menu and choose Properties.
    Python is not recognized as an internal or external command, operable program or batch file jenkins
    Press Windows key + Pause Key or right-click on This PC and choose Properties
  2. Inside the System Properties menu, click on the Advanced system settings link using the sidebar in the left-hand side.
    Python is not recognized as an internal or external command, operable program or batch file jenkins
    Advanced System settings
  3. In the System Properties menu, go to the Advanced tab and click on the Environment Variables button (bottom-section of the screen).
    Python is not recognized as an internal or external command, operable program or batch file jenkins
    Click on Environment Variables in the Advanced tab
  4. Once you get into the Environment Variables menu, select the Path entry in the System variables section and then click the Edit button.
    Python is not recognized as an internal or external command, operable program or batch file jenkins
    Select the PATH entry from the System Variables menu and click on Edit
  5. Next, click the New button and add Python’s path at the end of the list. Keep in mind that you can separate multiple paths by semicolons.
    Python is not recognized as an internal or external command, operable program or batch file jenkins
  6. Click Ok to save the changes, then try to run a Python command from Command Prompt. If the steps above were performed correctly you should have no issues inputting commands without specifying the full Python path.

Yessenia Mata - July 20, 2022

Python is one of the most used programming languages today, and given its popularity, it’s no wonder you are eager to start coding with it.

If you just installed Python on Windows, you may run into an issue in the command prompt that doesn’t allow you to execute any code. Since the problem is at execution, even if you just typed a Python code into the console, you can guess that it’s not a coding problem and rather a setup problem — and you’d be right.

The Windows command prompt relies on information in the computer’s libraries and packages to run some commands. For executing Python, Windows checks environmental variables on the computer to know where to find the file that will execute Python. If it doesn’t find it, then the Python code is not recognized as an internal or external command, operable program or batch file message is displayed.

It is not common for users programming on computers such as a Mac to see this error, since Python comes pre-installed on macOS. If you have a Mac and want to uninstall a Python version you downloaded, follow these steps.

What is causing the ‘Python’ is not recognized as an internal or external command, operable program or batch file” error?

Developers using a Windows machine may find this error when they try to run Python. This could be due to the Windows version being outdated, or if some settings were deleted. The underlying reason for the error that the full path to the correct Python distribution has to be saved in your computer’s Environmental Variables list.

This error can be easily addressed by adding your PATH environment variable.

Adding Python to the Windows PATH Environment Variable

Doing this can prove confusing if it’s your first time. So, we’ll go over the process of choosing the correct path to copy in Step 1. Then, we’ll move on to copying that path in the appropriate spot in your system’s environment variables in Step 2.

Step 1: Look in your programs for the Python folder where the version you installed is and copy the file location path. 1. Search your system for “python”. Right-click on the one that has Python, the version number, then (64-bit) and choose “Open file location”.

2. The file manager application should open along with the search results for python. If the Type column for python says ‘Shortcut’, then right-click again and choose “Open file location”.

Python is not recognized as an internal or external command, operable program or batch file jenkins

3. You should see “Application” under “Type”:

Python is not recognized as an internal or external command, operable program or batch file jenkins

4. Right-click again and choose “Properties”. Copy the “Location” path.

Python is not recognized as an internal or external command, operable program or batch file jenkins

Step 2: Add to the PATH Environment Variables 1. From the system search icon, type “environment variables”. Click and open the result.

2. You’ll see your variables here. Select the PATH variable and click the “Edit” button.

Python is not recognized as an internal or external command, operable program or batch file jenkins

3. In the following window, click “New” and paste the path you copied in Step 1.

Python is not recognized as an internal or external command, operable program or batch file jenkins

"Career Karma entered my life when I needed it most and quickly helped me match with a bootcamp. Two months after graduating, I found my dream job that aligned with my values and goals in life!"

Venus, Software Engineer at Rockbot

Python is not recognized as an internal or external command, operable program or batch file jenkins

4. Click “OK” to save.

If you have an older Windows version (such as Windows 7):

  1. From the Start Menu, right-click My Computer (could also be My PC or File Explorer).
  2. Select Advanced System Settings.
  3. In the Advanced Tab, Click on the Environmental Variables button.
  4. Find “Path” in the System Variables list and select “New”.
  5. Finally, paste the path you copied earlier in Step 1. If your system has lots of paths linked by semicolons, append the path by prefacing it with a semi-colon also.
  6. Click “OK” to save.

Try running Python again at the command prompt. Remember you may have to close and reopen the command prompt for the changes to work.

Alternative Options

You could also try type in “py” instead of “python”. This should let you use Python without returning the error message. But if you want to be able to use the full word in your code — “python” — then follow the steps above.

Python is not recognized as an internal or external command, operable program or batch file jenkins

If you are downloading a recent version of Python, there may already be an option that will automatically add Python to the system path so that you don’t have to. Look for “Add to Environmental Variables” and check it.

Conclusion

In summary, if this error message appears even if you know you installed python, it’s very likely it’s an environment variable issue. Just follow the steps above and try again. If you find it too complicated, you can also just reinstall Python and carefully check that you opt for the “Add to Environmental Variables” option.

Bugs and system discrepancies can often be fixed by installing the latest version of both your operating system and the application/program you’re trying to use. Not everyone has that option, however. For example you may be using a work laptop on which you don’t have certain needed permissions, or an older one you don’t want to part with. Read more about using Python on Windows here . Good Luck!

About us: Career Karma is a platform designed to help job seekers find, research, and connect with job training programs to advance their careers. Learn about the CK publication.

  • Python is not recognized as an internal or external command, operable program or batch file jenkins

    Want to take action?

    Get matched with top bootcamps

About the author: Yessenia is a technical writer at Career Karma. In addition to contributing to Career Karma as a writer, Yessenia currently works in IT in the San Francisco Bay Area. She has experience with programming languages including Java, Python, HTML, CSS, and JavaScript and is double majoring in CNIT and Computer Science.