banner



How To Change Default Python Version Windows

If you are a beginner, and so this article is for yous. As a beginner, you might face problems in setting a proper path for python. In today's tutorial, we will learn how to set a default path for python whenever nosotros install python into our system.

Introduction

Unlike well-nigh operating systems such as Unix, Windows does not include a system-supported installation of Python. To run Python conveniently from acontrol prompt, you might consider changing some default environs variables in Windows. To temporarily setenvironment variables, open Command Prompt and use the gear up command:

C:\>set PATH=C:\Plan Files\Python 3.half dozen; %PATH%

Why to set up a path for python?

If you've installed Python in Windows using the default installation options, then the path to Python will not be added to the Windows Path variable. The Path variable lists the directories that volition be searched for executing when you lot type a command in the command prompt. By adding the path to the Python executable, you will be able to access python.exe just by typing the python keyword in your command prompt. You volition non need to specify the full path to the program.

Let u.s.a. see what happens if we enter thepython command in the command prompt and the path to that executable is not added to the Path variable:

C:\>python 'python' is not recognized as an internal or external command, operable programme or batch file.

As you lot tin meet from the in a higher place output, the command was not found. Therefore, to runpython.exe, you volition need to specify the full path to the executable.

How to select default path while installing python?

There is an piece of cake way to gear up the default path during installing the Python. Every python installer comes with an option to add a python path into environmental variables. This will ensure that you can run python from your terminal. To do this –

  1. Get Python Installer from python.org.
  2. Get the installer and an installation window volition appear.
  3. Printing the "Add together Python X.X to your PATH" option and install the python.

This manner yous tin prepare a default path without any headache. If you already accept python installed and do not want to reinstall it, so movement on to the next methods.

How to set up a default python path for Windows manually?

To permanently modify the defaultsurround variables : My Calculator > Properties > Advanced Organization Settings > Environment Variables > Edit

Steps to follow in item.

  • Right-click on 'My Computer' or 'This PC.' :-To navigate to the Windows Environment Variables screen, where y'all can add/edit your paths, right-click on the 'This PC' icon. Then, select 'Properties.'
Steps to follow in detail to set path
This PC > Properties
  • Select 'Backdrop' at the lesser of the Context Menu.: – After selecting the properties, the settings popular up.
  • Next, select 'Avant-garde organization settings.'
Advanced system settings
  • Check 'Surround Variables...' in the Advanced Tab.: After pressing on the advance settings, some other window comes upwardly which shows the Environment Variable pick.
Environment Variables
  • Under 'Organisation Variables, ' Bank check on the New push button in the top half of the dialog to make a newuser variable.
New button in the top half of the dialog to make a new user variable.
  • A new user dialog box pop ups which contain Variable name and variable value.
default path python

Earlier yous type any values, you'll need to locate the relevant Python paths. The paths that y'all'll need to get are:

  • copy the python path as show in the epitome below
Python Scripts path

Now permit'due south fill theNew User Variable box that you saw earlier:

For theVariable name, blazon 'Path.' For theVariable value, copy the full Python application path, then utilise a semicolon.

Now select OK

Using python from Command Prompt

  1. Printing on the start card.
  2. Type Control Prompt and open it
  3. Type "python."
    1. A response from the python interpreter comes, i.e., it will show the python version currently installed in your arrangement else.
    2. You will become an error message that volition be written as "python is not recognized as an internal or external command." This means that in that location is something wrong with the path variable setting.

Checking of python path

  1. Press on the start bill of fare.
  2. Type Command Prompt and open it
  3. Type "python."
  4. Now type the following code.
import os os.environ['PYTHONPATH']          
          OUTPUT:-          'C:\Program Files\Python 3.6'

How to handle multiple paths in python?

You may have two versions of python installed in windows in your organization, let's say two.7 and 3.9. You lot want to run one of your projects in the python 2.7 version and some other project in the 3.9 version. So the trouble that lands up here is how you can specify which version you want to use for a specific python project?

So, to check all the versions of python installed in your windows environment , just type

py -0p in control prompt
How to handle multiple paths in python?
how to check all the versions installed in yous organization

And so, today I will show yous ii methods of how to manage multiple python paths in windows?

Method one: By defining the path of the versions

Whenever you try to run Python in the control prompt, it searches the %PATH% environment variable and checks for an executable file which can either be a batch file (.bat), command file (.exe), or any other executable file (.exe) that matches the name given. Once the correct file is found, it executes the programme using that file. Now, if you lot accept 2 versions of Python installed on your system (Python two.seven and 3.9), then the path variable will contain the location of both the directories. But, at that place is a problem. The problem is once Windows finds the first match, it volition stop examining whatsoever other path.

To overcome this problem, you lot take to phone call one or both applications using their path explicitly. For instance, equally y'all can see below, I take two versions of Python installed on my system.

  • To execute python 2.7 you must call C:\Python27\python.exe
path of the versions
Executing python 2.7 using path
  • To execute python 3.9 we had to blazon python3.9.exe
default path python
Accessing python 3.ix

This method is one of the simplest method for managing multiple paths of python.

Method two: Creating a shortcut

If you want to avoid using the unabridged path, create a shortcut for each python.exe file and rename information technology as python27 and python39.

In order to create the shortcuts, follow the given steps:

  • Navigate to the folder containing the Python version you want to create a shortcut for.
creating shortcuts
  • Right-click and create a shortcut.
run as administrator
  • Rename the shortcut.

To run a file in python 2.7

python 2.7 default path

Also, Cheque Out Editors Choice:

Conclusion

I hope this article helps you lot in setting a proper path for python in Windows operating arrangement. As a beginner, y'all might confront difficulties, but no worries, keep reading our tutorials on python and beingness a pro. Drib a annotate if you lot have doubts. Nosotros are just one reply abroad. Till then, keep reading.

Happy Pythoning Geeks!!

Source: https://www.pythonpool.com/default-python-path/

Posted by: moodywasso1962.blogspot.com

0 Response to "How To Change Default Python Version Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel