1

I have renamed python.exe to python37.exe to avoid conflict with other versions. It works for running python, but if I run pip37.exe (located in /Scripts) I get the following error:

Fatal error in launcher: Unable to create process using '"c:\python37-32\python.exe"  "C:\Python37-32\Scripts\pip37.exe"

Is there a way to keep python.exe renamed to python37.exe, but keep all python tools working?

Håken Lid
  • 18,252
  • 8
  • 40
  • 58
  • Switch to linux, and it's trivial to fix ;). In python 3.7, pip is part of the standard library, so the recommended way to run pip is `python -m pip`. I recommend you do that instead of using `pip37.exe`. The `pip` / `pip37.exe` executable is pretty much just a wrapper around that command anyway. – Håken Lid Oct 20 '18 at 11:23
  • You can use a symbolic link beside the executable (e.g. python37.exe -> python.exe) and run the specific version using the symlink. This will have no effect on fully-qualified paths in embedded scripts (e.g. embedded in pip37.exe). However, it still requires managing the order of installations in `PATH` to set which version runs via unqualified `python` in a command prompt. This is most easily addressed by activating a virtual environment, as created by Python 3's venv module. – Eryk Sun Oct 20 '18 at 18:49

2 Answers2

4

This sounds like A BAD IDEA.

There are tools designed to help you manage exactly this sort of thing. The best of which imho is pyenv: https://github.com/pyenv/pyenv

It's quite simple to install. It takes a bit of getting used to – wrapping your head around virtual environments – but it makes it all so much easier to work with ultimately.

E.g. On my system I have the following versions of python:

pyenv versions
  system
  2.7.10
* 3.5.6 (set by /Users/.pyenv/version)
  3.5.6/envs/core4
  3.6.4
  3.6.4/envs/core5
  core4
  core5

The one with the asterisk is currently the global version, which will be the one used from any default shell. I can change that using pyenv global 3.6.4 for example. I can also create virtual environments. E.g. core4 and core5 are virtual environments I created for specific projects. Each of these will have their own different libraries installed by pip install and differing python versions. You can activate a virtualenv for a given shell session e.g. pyenv activate core5.

And if you're thinking "what on earth does this have to do with Windows", look here: https://duckduckgo.com/?q=Windows+Subsystem+for+Linux&atb=v93-1__&ia=web and here: http://timmyreilly.azurewebsites.net/python-pip-virtualenv-installation-on-windows/

geoidesic
  • 3,904
  • 3
  • 25
  • 49
3

On Windows Python installs PyLauncher. You don't need virtual environments or renaming tricks. py.exe is in the standard Windows path, has command line switches to pick the Python version to use, and enables using "shebangs" to specify what version of Python to run for scripts:

py script.py          # Run the latest Python installed (or specified by PY_PYTHON environment variable).
py -2 script.py       # Run the latest Python 2 version installed.
py -3 script.py       # Run the latest Python 3 version installed.
py -2.7 script.py     # Run the specific Python version.
py -2.7-32 script.py  # Run the 32-bit specific Python version.
py -0                 # List Python versions installed.

Scripts can use shebangs similar to Linux:

#!python2
#!python3
#!python2.7
#!python2.7-32 

To run pip with a specific version:

py -2.7 -m pip install ...

If you need still would like a virtual environment with a specific Python version, you can specify the version (e.g. -3) and use:

py -3 -m venv <my_env_name>     # to create an virtual environment
<my_env_name>/scripts/activate  # to activate that environment

Activation adds the virtual environment to the path, so python (not py) will run in that environment. the Scripts directory in that environment will also be added to the path, so pip can be run directly as well to install packages in that environment.

Mark Tolonen
  • 132,868
  • 21
  • 152
  • 208