vim: how to set up py.exe as python interpreter - python

I'm using vim and multiple python versions (2.7, 3.3) on windows at my work without administrative privileges. Earlier i used portablepython which is ok to run the program which i working on, but it dropped me warning messages when i opened a python script in vim while jedi-vim was installed (i think the occurred by the modified python27.dll). So i installed python at home (with the option "just for me"), copied it to dropbox and downloaded to work pc and set up registry keys and the PATH variable. The python itself works fine (including the python launcher), but the vim plugins fails if python33 is ahead of python27 in the PATH.
Can is set up vim to use py.exe instead of python.exe as interpreter?

For the :python integration into Vim, no Python executable is used. Instead, Vim must be compiled with support for a particular Python version, and that DLL must then be accessible through PATH during runtime. (It can also be statically linked, but the +python/dyn is the default on Windows.)
Therefore, it is crucial that the correct pythonXXX.dll version can be located through PATH, as you've already found out.

Related

VSCode finding different python by default than the first one on the path

I'm using vscode on macOS and using nix to manage my environment. I do have python3.9 installed via homebrew as my system-default python, but I'm working on a project using a nix environment that is setting my path such that the only python executable available is python 3.8.
$ which python
/nix/store/mr2p1ycgj3wfppbw8ry2wwxg9r0xjz0z-python3-3.8.8-env/bin/python
$ whence python
/nix/store/mr2p1ycgj3wfppbw8ry2wwxg9r0xjz0z-python3-3.8.8-env/bin/python
$ whence python3
/nix/store/mr2p1ycgj3wfppbw8ry2wwxg9r0xjz0z-python3-3.8.8-env/bin/python
$ code .
The VSCode instance that comes up finds my 3.9 install as the default interpreter...
This causes a problem because the interpreter that's put on the path by nix is also the one with all my packages installed for this particular project, including developer utilities like black, flake8, pylint, etc... and my default 3.9 install does not necessarily have those.
It seems like there's a mechanism by which the Python extension discovers various python installs (I see in the extension output things where it tries to source virtualenvs and query pyenv), so what I think is happening is that it's finding a bunch of different python interpreters and blindly defaulting to the newest.
Is there any way to override the way the Python extension discovers python installs? I just want it to use the python interpreter that it finds on the path by default. I know I can override the interpreter per-project via the .vscode/settings.json, but that's a bit tedious to do for every project, and the way nix works that path may change occasionally. I already have "python.pythonPath": "python" in my vscode settings (which is the default anyway) - I was hoping that would work... it does not.
When we use "code." to open VS Code from the system terminal outside VS Code, it uses the latest version (highest version) of python installed in the system by default.
For directly opening an existing folder (containing python files) from VS Code, it defaults to using the python environment used last time, and for a new project that has not been selected, it also defaults to using the latest version (highest version) of python installed in the system .
You could click on the python environment in the lower left corner of VS Code, and then switch to the desired python environment in the options. In addition, it is recommended that you open the previously used project from VS Code (click File, Open Folder) and use the virtual environment in VS Code.

How to set python 3.x priority? [duplicate]

I installed Python 2.6 and Python 3.1 on Windows 7 and set environment variable: path = d:\python2.6.
When I run python in cmd, it displays the python version 2.6, which is what I want!
But, when I wrote a script in a bat file and ran it, the displayed python version was 3.1.
import sys
print (sys.version)
What's going on here?
This is if you have both the versions installed.
Go to This PC → Right-click → Click on Properties → Advanced System Settings.
You will see the System Properties. From here navigate to the Advanced Tab -> Click on Environment Variables.
You will see a top half for the user variables and the bottom half for System variables.
Check the System Variables and double-click on the Path (to edit the Path).
Check for the path of Python(which you wish to run i.e. Python 2.x or 3.x) and move it to the top of the Path list.
Restart the Command Prompt, and now when you check the version of Python, it should correctly display the required version.
The Python installer installs Python Launcher for Windows. This program (py.exe) is associated with the Python file extensions and looks for a "shebang" comment to specify the python version to run. This allows many versions of Python to co-exist and allows Python scripts to explicitly specify which version to use, if desired. If it is not specified, the default is to use the latest Python version for the current architecture (x86 or x64). This default can be customized through a py.ini file or PY_PYTHON environment variable. See the docs for more details.
Newer versions of Python update the launcher. The latest version has a py -0 option to list the installed Pythons and indicate the current default.
Here's how to check if the launcher is registered correctly from the console:
C:\>assoc .py
.py=Python.File
C:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%1" %*
Above, .py files are associated with the Python.File type. The command line for Python.File is the Python Launcher, which is installed in the Windows directory since it is always in the PATH.
For the association to work, run scripts from the command line with script.py, not "python script.py", otherwise python will be run instead of py. If fact it's best to remove Python directories from the PATH, so "python" won't run anything and enforce using py.
py.exe can also be run with switches to force a Python version:
py -3 script.py # select latest Python 3.X version to be used.
py -3.6 script.py # select version 3.6 specifically.
py -3.9-32 script.py # select version 3.9 32-bit specifically.
py -0 # list installed Python versions (latest PyLauncher).
Additionally, add .py;.pyw;.pyc;.pyo to the PATHEXT environment variable and then the command line can just be script with no extension.
Running 'py' command will tell you what version you have running. If you currently running 3.x and you need to switch to 2.x, you will need to use switch '-2'
py -2
If you need to switch from python 2.x to python 3.x you will have to use '-3' switch
py -3
If you would like to have Python 3.x as a default version, then you will need to create environment variable 'PY_PYTHON' and set it's value to 3.
If you know about Environment variables and the system variable called path, consider that any version of any binary which comes sooner, will be used as default.
Look at the image below, I have 3 different python versions but python 3.8 will be used as default since it came sooner than the other two. (In case of mentioned image, sooner means higher!)
If you are a Windows user and you have a version of Python 3.3 or greater, you should have the Python Launcher for Windows installed on your machine, which is the recommended way to use for launching all python scripts (regardless of python version the script requires).
As a user
Always type py instead of python when running a script from the command line.
Setup your "Open with..." explorer default program association with C:\Windows\py.exe
Set the command line file extension association to use the Python Launcher for Windows (this will make typing py optional). In an Admin cmd terminal, run:
ftype Python.File="C:\Windows\py.exe" "%L" %*
ftype Python.NoConFile="C:\Windows\pyw.exe" "%L" %*
Set your preferred default version by setting the PY_PYTHON environment variable (e.g. PY_PYTHON=3.11). You can see what version of python is your default by typing py. You can also set PY_PYTHON3 or PY_PYTHON2 to specify default python 3 and python 2 versions (if you have multiple).
If you need to run a specific version of python, you can use py -M.m (where M is the major version and m is the minor version). For example, py -3 will run any installed version of python 3.
List the installed versions of python with py -0.
As a script writer
Include a shebang line at the top of your script that indicates the major version number of python required. If the script is not compatible with any other minor version, include the minor version number as well. For example:
#!/usr/bin/env python3
Note: (see this question) If python3 does not work for you, ensure that you've installed python from the Windows Store (e.g. via winget install --id 9NRWMJP3717K, as the winget package Python.Python.3.11 does not appear to include a python3.exe).
You can use the shebang line to indicate a virtual environment as well (see PEP 486 below).
See also
PEP 397 -- Python launcher for Windows
PEP 486 -- Make the Python Launcher aware of virtual environments
Python Launcher for Windows - User Guide
See here for original post
;
; This is an example of how a Python Launcher .ini file is structured.
; If you want to use it, copy it to py.ini and make your changes there,
; after removing this header comment.
; This file will be removed on launcher uninstallation and overwritten
; when the launcher is installed or upgraded, so don't edit this file
; as your changes will be lost.
;
[defaults]
; Uncomment out the following line to have Python 3 be the default.
;python=3
[commands]
; Put in any customised commands you want here, in the format
; that's shown in the example line. You only need quotes around the
; executable if the path has spaces in it.
;
; You can then use e.g. #!myprog as your shebang line in scripts, and
; the launcher would invoke e.g.
;
; "c:\Program Files\MyCustom.exe" -a -b -c myscript.py
;
;myprog="c:\Program Files\MyCustom.exe" -a -b -c
Thus, on my system I made a py.ini file under c:\windows\ where py.exe exists, with the following contents:
[defaults]
python=3
Now when you Double-click on a .py file, it will be run by the new default version. Now I'm only using the Shebang #! python2 on my old scripts.
Edit registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\python.exe\default
Set default program to open .py files to python.exe
This work for me.
If you want to use the python 3.6 you must move the python3.6 on the top of the list.
The same applies to the python2.7
If you want to have the 2.7 as default then make sure you move the python2.7 on the very top on the list.
step 1
step 2
step 3
then close any cmd command prompt and opened again, it should work as expected.
python --version
>>> Python 3.6
This worked for me:
Go to
Control Panel\System and Security\System
select
Advanced system settings from the left panel
from Advanced tab click on Environment Variables
In the System variables section search for (create if doesn't exist)
PYTHONPATH
and set
C:\Python27\;C:\Python27\Scripts;
or your desired version
You need to restart CMD.
In case it still doesn't work you might want to leave in the PATH variable only your desired version.
With Python version 2.7, 3.7, 3.9 and 3.11 installed on my Windows 11 OS, the above solutions didn't works for me.
The command py --help give some hints to set python version, example:
usage:
[...]
If an exact version is not given, using the latest
version can be overridden by any of the following, (in priority
order):
👉 From [defaults] in py.ini in your %LOCALAPPDATA%\py.ini
The easiest way I found to set a specific default Python version is to create/edit a py.ini file under %LOCALAPPDATA%\py.ini.
Content of py.ini 👇
[defaults]
python=3.7
Console output with Administrator and User right 💡:
C:\Users\bob>py --version
Python 3.7.9
If you are on Windows, use the ASSOC command to change the default python version for python programs.
assoc .py=<Python 3.1 directory>
Now that Python 3.3 is released it is easiest to use the py.exe utility described here:
http://www.python.org/dev/peps/pep-0397/
It allows you to specify a Python version in your script file using a UNIX style directive. There are also command line and environment variable options for controlling which version of Python is run.
The easiest way to get this utility is to install Python 3.3 or later.
Nothing above worked, this is what worked for me:
ftype Python.File=C:\Path\to\python.exe "%1" %*
This command should be run in Command prompt launched as administrator
Warning: even if the path in this command is set to python35, if you have python36 installed it's going to set the default to python36. To prevent this, you can temporarily change the folder name from Python36 to xxPython36, run the command and then remove the change to the Python 36 folder.
Edit: This is what I ended up doing: I use Python Launcher.
https://stackoverflow.com/a/68139696/3154274
Check which one the system is currently using:
python --version
Add the main folder location (e.g. C/ProgramFiles) and Scripts location (C/ProgramFiles/Scripts) to Environment Variables of the system. Add both 3.x version and 2.x version
Path location is ranked inside environment variable. If you want to use Python 2.x simply put path of python 2.x first, if you want for Python 3.x simply put 3.x first
This uses python 2
Since my problem was slightly different and none of the above worked for me, I'll add what worked for me. I had installed the new python launcher for python 3.10 today, installed the version through it, but the command window did not recognise the version. Instead, it listed older python3 versions I had on my computer.
Finally, in the windows programs list, I saw that I had two versions of the python launcher. I uninstalled the old one, and now python 3.10 shows up correctly when running py -0 and is the chosen version when running py.
Apologies if this is a noob answer, I am new to all this.
I had same problem and solve it by executing the installation file again. when you do that python automatically knows you have installed it before so it recommends you 3 options! select modify and select all packages you want to modify then in the next page you can check if new version of python is added to your environment variables or not. check it and then execute modification. I did and it solved.
Use SET command in Windows CMD to temporarily set the default python for the current session.
SET PATH=C:\Program Files\Python 3.5
Try modifying the path in the windows registry (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment).
Caveat: Don't break the registry :)

How to run different python versions in cmd [duplicate]

This question already has answers here:
How to run multiple Python versions on Windows
(22 answers)
Closed 6 years ago.
How can I configure windows command dialog to run different python versions in it? For example when I type python2 it runs python 2.7 and when I type python3 it runs python 3.3? I know how to configure environment variables for one version but two? I mean something like Linux terminal.
I also met the case to use both python2 and python3 on my Windows machine. Here's how i resolved it:
download python2x and python3x, installed them.
add C:\Python35;C:\Python35\Scripts;C:\Python27;C:\Python27\Scripts to environment variable PATH.
Go to C:\Python35 to rename python.exe to python3.exe, also to C:\Python27, rename python.exe to python2.exe.
restart your command window.
type python2 scriptname.py, or python3 scriptname.py in command line to switch the version you like.
Python 3.3 introduces Python Launcher for Windows that is installed into c:\Windows\ as py.exe and pyw.exe by the installer. The installer also creates associations with .py and .pyw. Then add #!python3 or #!python2 as the first lline. No need to add anything to the PATH environment variable.
Update: Just install Python 3.3 from the official python.org/download. It will add also the launcher. Then add the first line to your script that has the .py extension. Then you can launch the script by simply typing the scriptname.py on the cmd line, od more explicitly by py scriptname.py, and also by double clicking on the scipt icon.
The py.exe looks for C:\PythonXX\python.exe where XX is related to the installed versions of Python at the computer. Say, you have Python 2.7.6 installed into C:\Python27, and Python 3.3.3 installed into C:\Python33. The first line in the script will be used by the Python launcher to choose one of the installed versions. The default (i.e. without telling the version explicitly) is to use the highest version of Python 2 that is available on the computer.
I would suggest using the Python Launcher for Windows utility that was introduced into Python 3.3. You can manually download and install it directly from the author's website for use with earlier versions of Python 2 and 3.
Regardless of how you obtain it, after installation it will have associated itself with all the standard Python file extensions (i.e. .py, .pyw, .pyc, and .pyo files). You'll not only be able to explicitly control which version is used at the command-prompt, but also on a script-by-script basis by adding Linux/Unix-y shebang #!/usr/bin/env pythonX comments at the beginning of your Python scripts.

Python 3.2 doesn't work with python 2.7

I already have python 2.7 (installed using activepython). I'm trying to use python 3.2 just to learn more about it so i downloaded it from python.org
python 2.7 still works perfectly, but python 3.2 gives me this error when i try to open the ide.
and then I see the send error window, if i install python 3.2 using activepython i see the same error.
I'm using windows xp pro sp3 32 bit and i had the same error on sp2... How do I fix it?
EDIT #Zuljin
This is the first time that i use dependancy walker so could you give me a hand please
this is what i see
what does that mean? I already have these files...
I saw a lot of answers here. But, I think the file that you are trying to run is not correct
C:\Python32\Pythonw.exe
is not the one you use to open idle.
Open
C:\Python32\Lib\idlelib\idle.pyw
Python 2.x and 3.x can cohabitate perfectly in win xp and win 7, either 32 or 64 bits.
If you first installed the ActiveState Python distribution, be careful when installing python-3.2.2.msi.
When you arrive to the customize python 3.2.2 screen, (un)check 'register extensions' to make the feature unavailable (that is: do not register extensions).
I have installed this way both distributions in different computers without any problem so far.
Note: Check your environment variables. Only python 2.7 should be in the path (if you installed before the two distros you could have them both in the path. Remove python 3.2 path)
Edit:
From Ankit post I realized that in fact you were trying to open IDLE, maybe.
If you follow my installation instructions when you call idle.bat from the py3.2 idlelib folder you actually get idle for python 2.7 as this is what the call find in the windows path. To be able to open idle for py3.2 in the presence of python 2.7 as the registered python, I use a .bat file modified from that in the distribution:
idle_stay.bat
#echo off
rem Working IDLE bat for Windows - Custom bat for py3k as secundary python
C:\Python32\pythonw C:\Python32\Lib\idlelib\idle.pyw %1 %2 %3 %4 %5 %6 %7 %8 %9
The name idle_stay.bat is because I put this file in the folder where the official idle.bat is (C:\Python32\Lib\idlelib\idle_stay.bat). In this way it does not get overwritten each time I unisntall and reinstall a new version of python 3
It seems to me you have associated a *.py or *.pyw file extension type to some version of python.exe and/or pythonw.exe you aren't clear about. This is often, but not exclusively done from within Microsoft's "explore.exe" File Manager (I believe in Options).
I disagree that this is a reliable method:
C:\Python32\Lib\idlelib\idle.pyw
as this method will run whichever program is assigned to the "pyw" extension. That could be:
C:\Python32\pythonw.exe
or
C:\Python26\python.exe
or whatever might have happened to your file extension association as per OS or bad PATH environment variable setting. It is better to do something like this:
C:\Python32\pythonw.exe C:\Python32\Lib\idlelib\idle.pyw
where you are explicidly telling the OS to run the python executable from a specific path and selecting a specific python script in the file/folder hiearchy.
Another thing you can try to gather info is just:
python.exe -V
which will tell you the version number.
Another thing you can do:
Open a DOS command prompt and type:
set PATH=C:\Windows;C:\Windows\system32;C:\Python32
python.exe and note the version and whether is runs.
exit()
exit
Once working debug your PATH. You can use this Python script to gather intel.
If you turned off your WinXP findfile stuff (like I have) you can use this script:
inpath.py can help shed some light.
Run this python script like this:
Drop to a DOS prompt
cd to your folder with a working python.exe version.
and type python.exe inpath.py python*
where inpath is in that same folder for this test/debug.
inpath.py will search your path for all files associated as "runable" in your OS and that is in your "PATH" with the python*.* pattern.

How Should I Set Default Python Version In Windows?

I installed Python 2.6 and Python 3.1 on Windows 7 and set environment variable: path = d:\python2.6.
When I run python in cmd, it displays the python version 2.6, which is what I want!
But, when I wrote a script in a bat file and ran it, the displayed python version was 3.1.
import sys
print (sys.version)
What's going on here?
This is if you have both the versions installed.
Go to This PC → Right-click → Click on Properties → Advanced System Settings.
You will see the System Properties. From here navigate to the Advanced Tab -> Click on Environment Variables.
You will see a top half for the user variables and the bottom half for System variables.
Check the System Variables and double-click on the Path (to edit the Path).
Check for the path of Python(which you wish to run i.e. Python 2.x or 3.x) and move it to the top of the Path list.
Restart the Command Prompt, and now when you check the version of Python, it should correctly display the required version.
The Python installer installs Python Launcher for Windows. This program (py.exe) is associated with the Python file extensions and looks for a "shebang" comment to specify the python version to run. This allows many versions of Python to co-exist and allows Python scripts to explicitly specify which version to use, if desired. If it is not specified, the default is to use the latest Python version for the current architecture (x86 or x64). This default can be customized through a py.ini file or PY_PYTHON environment variable. See the docs for more details.
Newer versions of Python update the launcher. The latest version has a py -0 option to list the installed Pythons and indicate the current default.
Here's how to check if the launcher is registered correctly from the console:
C:\>assoc .py
.py=Python.File
C:\>ftype Python.File
Python.File="C:\Windows\py.exe" "%1" %*
Above, .py files are associated with the Python.File type. The command line for Python.File is the Python Launcher, which is installed in the Windows directory since it is always in the PATH.
For the association to work, run scripts from the command line with script.py, not "python script.py", otherwise python will be run instead of py. If fact it's best to remove Python directories from the PATH, so "python" won't run anything and enforce using py.
py.exe can also be run with switches to force a Python version:
py -3 script.py # select latest Python 3.X version to be used.
py -3.6 script.py # select version 3.6 specifically.
py -3.9-32 script.py # select version 3.9 32-bit specifically.
py -0 # list installed Python versions (latest PyLauncher).
Additionally, add .py;.pyw;.pyc;.pyo to the PATHEXT environment variable and then the command line can just be script with no extension.
Running 'py' command will tell you what version you have running. If you currently running 3.x and you need to switch to 2.x, you will need to use switch '-2'
py -2
If you need to switch from python 2.x to python 3.x you will have to use '-3' switch
py -3
If you would like to have Python 3.x as a default version, then you will need to create environment variable 'PY_PYTHON' and set it's value to 3.
If you know about Environment variables and the system variable called path, consider that any version of any binary which comes sooner, will be used as default.
Look at the image below, I have 3 different python versions but python 3.8 will be used as default since it came sooner than the other two. (In case of mentioned image, sooner means higher!)
If you are a Windows user and you have a version of Python 3.3 or greater, you should have the Python Launcher for Windows installed on your machine, which is the recommended way to use for launching all python scripts (regardless of python version the script requires).
As a user
Always type py instead of python when running a script from the command line.
Setup your "Open with..." explorer default program association with C:\Windows\py.exe
Set the command line file extension association to use the Python Launcher for Windows (this will make typing py optional). In an Admin cmd terminal, run:
ftype Python.File="C:\Windows\py.exe" "%L" %*
ftype Python.NoConFile="C:\Windows\pyw.exe" "%L" %*
Set your preferred default version by setting the PY_PYTHON environment variable (e.g. PY_PYTHON=3.11). You can see what version of python is your default by typing py. You can also set PY_PYTHON3 or PY_PYTHON2 to specify default python 3 and python 2 versions (if you have multiple).
If you need to run a specific version of python, you can use py -M.m (where M is the major version and m is the minor version). For example, py -3 will run any installed version of python 3.
List the installed versions of python with py -0.
As a script writer
Include a shebang line at the top of your script that indicates the major version number of python required. If the script is not compatible with any other minor version, include the minor version number as well. For example:
#!/usr/bin/env python3
Note: (see this question) If python3 does not work for you, ensure that you've installed python from the Windows Store (e.g. via winget install --id 9NRWMJP3717K, as the winget package Python.Python.3.11 does not appear to include a python3.exe).
You can use the shebang line to indicate a virtual environment as well (see PEP 486 below).
See also
PEP 397 -- Python launcher for Windows
PEP 486 -- Make the Python Launcher aware of virtual environments
Python Launcher for Windows - User Guide
See here for original post
;
; This is an example of how a Python Launcher .ini file is structured.
; If you want to use it, copy it to py.ini and make your changes there,
; after removing this header comment.
; This file will be removed on launcher uninstallation and overwritten
; when the launcher is installed or upgraded, so don't edit this file
; as your changes will be lost.
;
[defaults]
; Uncomment out the following line to have Python 3 be the default.
;python=3
[commands]
; Put in any customised commands you want here, in the format
; that's shown in the example line. You only need quotes around the
; executable if the path has spaces in it.
;
; You can then use e.g. #!myprog as your shebang line in scripts, and
; the launcher would invoke e.g.
;
; "c:\Program Files\MyCustom.exe" -a -b -c myscript.py
;
;myprog="c:\Program Files\MyCustom.exe" -a -b -c
Thus, on my system I made a py.ini file under c:\windows\ where py.exe exists, with the following contents:
[defaults]
python=3
Now when you Double-click on a .py file, it will be run by the new default version. Now I'm only using the Shebang #! python2 on my old scripts.
Edit registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\python.exe\default
Set default program to open .py files to python.exe
This work for me.
If you want to use the python 3.6 you must move the python3.6 on the top of the list.
The same applies to the python2.7
If you want to have the 2.7 as default then make sure you move the python2.7 on the very top on the list.
step 1
step 2
step 3
then close any cmd command prompt and opened again, it should work as expected.
python --version
>>> Python 3.6
This worked for me:
Go to
Control Panel\System and Security\System
select
Advanced system settings from the left panel
from Advanced tab click on Environment Variables
In the System variables section search for (create if doesn't exist)
PYTHONPATH
and set
C:\Python27\;C:\Python27\Scripts;
or your desired version
You need to restart CMD.
In case it still doesn't work you might want to leave in the PATH variable only your desired version.
With Python version 2.7, 3.7, 3.9 and 3.11 installed on my Windows 11 OS, the above solutions didn't works for me.
The command py --help give some hints to set python version, example:
usage:
[...]
If an exact version is not given, using the latest
version can be overridden by any of the following, (in priority
order):
👉 From [defaults] in py.ini in your %LOCALAPPDATA%\py.ini
The easiest way I found to set a specific default Python version is to create/edit a py.ini file under %LOCALAPPDATA%\py.ini.
Content of py.ini 👇
[defaults]
python=3.7
Console output with Administrator and User right 💡:
C:\Users\bob>py --version
Python 3.7.9
If you are on Windows, use the ASSOC command to change the default python version for python programs.
assoc .py=<Python 3.1 directory>
Now that Python 3.3 is released it is easiest to use the py.exe utility described here:
http://www.python.org/dev/peps/pep-0397/
It allows you to specify a Python version in your script file using a UNIX style directive. There are also command line and environment variable options for controlling which version of Python is run.
The easiest way to get this utility is to install Python 3.3 or later.
Nothing above worked, this is what worked for me:
ftype Python.File=C:\Path\to\python.exe "%1" %*
This command should be run in Command prompt launched as administrator
Warning: even if the path in this command is set to python35, if you have python36 installed it's going to set the default to python36. To prevent this, you can temporarily change the folder name from Python36 to xxPython36, run the command and then remove the change to the Python 36 folder.
Edit: This is what I ended up doing: I use Python Launcher.
https://stackoverflow.com/a/68139696/3154274
Check which one the system is currently using:
python --version
Add the main folder location (e.g. C/ProgramFiles) and Scripts location (C/ProgramFiles/Scripts) to Environment Variables of the system. Add both 3.x version and 2.x version
Path location is ranked inside environment variable. If you want to use Python 2.x simply put path of python 2.x first, if you want for Python 3.x simply put 3.x first
This uses python 2
Since my problem was slightly different and none of the above worked for me, I'll add what worked for me. I had installed the new python launcher for python 3.10 today, installed the version through it, but the command window did not recognise the version. Instead, it listed older python3 versions I had on my computer.
Finally, in the windows programs list, I saw that I had two versions of the python launcher. I uninstalled the old one, and now python 3.10 shows up correctly when running py -0 and is the chosen version when running py.
Apologies if this is a noob answer, I am new to all this.
I had same problem and solve it by executing the installation file again. when you do that python automatically knows you have installed it before so it recommends you 3 options! select modify and select all packages you want to modify then in the next page you can check if new version of python is added to your environment variables or not. check it and then execute modification. I did and it solved.
Use SET command in Windows CMD to temporarily set the default python for the current session.
SET PATH=C:\Program Files\Python 3.5
Try modifying the path in the windows registry (HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment).
Caveat: Don't break the registry :)

Categories

Resources