Python Forum
How to re-register .py file extension to new moved Python dir (on Windows)?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to re-register .py file extension to new moved Python dir (on Windows)?
#1
Assume I installed Python v3.1.3 in the default installation directory

C:\Program Files\Python\

Now I decide to move this installation directory (without re-installlation) e.g. to

D:\devtools\Python\

Unfortunately simply moving the installation directory breaks the file associations.
The same applies when I want to use Pything from flash drive.

*.py file association still points to the old directory.
and Environment variable PATH still contains the old Python location too.

So how can I tell Python to re-register itself (for file associations and PATH) by using its current new directory?

Any solution for that?
Reply
#2
Find any .py file in explorer and right-click it. Choose "open with" and browse to your new python executable. Make sure to check the "always" box.

/regards
Reply
#3
Here how to change Environment Variables Path, remember to also add path to Scripts folder as image here.

Can use FileTypesMan for file associations.
Reply
#4
Ok, thank you.

Thats means I have manually to fiddle around with system settings and context menüs.

There is no simple

python.exe -register

commandline command which does the job for me?
Reply
#5
(Nov-05-2024, 11:36 AM)pstein Wrote: Thats means I have manually to fiddle around with system settings and context menüs.
Is common to to fix add stuff to Environment Variables Path,
when programming this is very low requirement to understand and make changes to.

Can also just use py,it bypass Environment Variables(py.exe get install to windows folder) and have been in Python 3 for long time
G:\div_code
λ py --version
Python 3.13.0

G:\div_code
λ py --help
Python Launcher for Windows Version 3.13.0

usage:
py [launcher-args] [python-args] [script [script-args]]
.....

uv is the new Python package and project manager for Python.
Can start with no Python install on OS,uv will download and install.
G:\div_code\py_313
λ uv venv --python 3.13.0 # Will get Python 3.13 and install
Using CPython 3.13.0
Creating virtual environment at: .venv
Activate with: .venv\Scripts\activate
 
G:\div_code\py_313
λ .venv\Scripts\activate
 
G:\div_code\py_313
(py_313) λ python --version
Python 3.13.0
Gribouillis likes this post
Reply
#6
(Nov-04-2024, 12:00 PM)pstein Wrote: Unfortunately simply moving the installation directory breaks the file associations.
The same applies when I want to use Pything from flash drive.

Same happens, if you move on Linux /usr/bin/python to another place, which is not in Path and then trying to run a Python program. The shell won't find the interpreter, because it's not in the PATH variable. On Windows, you have File Associations. You can see them in your Registry under the KEY: HKEY_CLASSES_ROOT\Python.CompiledFile\shell\open\command

Generally it's in the most cases not possible to move an installed program to another location without changing the registry/configuration.
Gribouillis likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create a new subclass in a Python extension based on an existing class voidtrance 6 1,371 Mar-25-2025, 06:37 PM
Last Post: voidtrance
  Can a windows file be 'remapped' in Linux ? jehoshua 3 886 Dec-07-2024, 03:33 AM
Last Post: jehoshua
  Executable file compiled by PyInstaller does not work on Windows 7 amusaber 1 1,792 Jul-11-2024, 02:59 PM
Last Post: DeaD_EyE
  Python C Extension Module loading issue on Cygwin mesibo 0 1,375 Sep-22-2023, 05:41 AM
Last Post: mesibo
  Pymodbus Write value to register stsxbel 10 13,909 Aug-18-2022, 01:42 PM
Last Post: DeaD_EyE
  Simple syntax to asynchronously get access to MODBUS register orion67 1 3,876 Jan-22-2022, 12:40 PM
Last Post: orion67
  batch file for running python scipt in Windows shell MaartenRo 2 3,040 Jan-21-2022, 02:36 PM
Last Post: MaartenRo
  Using a .bat file to execute simple anaconda commands in Windows 10 gacg1 0 5,791 Nov-30-2020, 03:24 PM
Last Post: gacg1
  Python broken if moved to a different folder ecastrotns 3 3,733 Oct-26-2020, 10:53 PM
Last Post: ecastrotns
  find file not knowing the extension Leon79 6 4,614 Jul-07-2020, 04:44 PM
Last Post: Leon79

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020