Home > front end >  Is it possible to have two distinct install of Python 3 of the same revision on a Windows system?
Is it possible to have two distinct install of Python 3 of the same revision on a Windows system?

Time:01-22

I know it possible to have two installs of Python of different versions on a Windows system. But I cannot manage to have two installs of the same revision (in my case 3.8.10) to coexist.

I'm designing an application that creates a Python process. That process needs to run from a specific version of Python with packages of specific versions installed on it. In order to fully control the Python install, decision was made to install it inside the application distribution directory, segregating it from any other Python installed on the system. No environment variable refers to it.

As part of the the deployment/install process for the application, a PowerShell script downloads the Python installer and installs Python and the necessary packages into the application distribution directory. The Python installer is invoked as follows:

.\\python-3.8.10-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0 TargetDir="$curDir\\Python" Include_exe=1 Include_lib=1 Include_pip=1 Include_tcltk=1 | Out-Null

It works well unless the system has already a Python install of the same version installed on it. In that case, running the installer will break the existing install, and not fully install the new one.

I tried to run the installer manually and I noticed that it is able, somehow, to detect that an install of the same revision exist on the system. In that case, it does not allow an new install. To do so, I would have to uninstall Python at its current location to be able to install it somewhere else. enter image description here

Is there a way to have two distinct installs of Python 3 of the same revision on a Windows system? And if yes, how can it be done?

CodePudding user response:

A better aproach instead of installing python again would be using virtual environments.

To create a new python env. Open the command line (Powershell) on Windows and navigate to the directory you want your python env to be.

  • Type python3 -m venv tutorial-env. This will create a new python virtual env named tutorial-env
  • To activate that env on Windows powershell type: tutorial-env\Scripts\activate.bat
  • To deactivate the env type deactivate

If you are wondering what python virtual environments do. They basically do what you are trying to do but without installing python globally again. When you create a new python env, a new python3 is placed in your env directory, in this case in the tutorial-env directory, and when you activate the environment, it replaces the python global path to the path in your env (in this case in tutorial-env). Now when you are on this virtual env and install new python packages, they will only be available when you activate that env.

For more information about virtual environments please refer to Python official docs.

  • Related