[Python-Dev] Python install layout and the PATH on win32 (original) (raw)

Paul Moore p.f.moore at gmail.com
Tue Mar 20 21:31:00 CET 2012


On 20 March 2012 19:22, VanL <van.lindberg at gmail.com> wrote:

There are a number of casual users that probably only have one version installed, but every python user/dev on windows that I know has one python that they consider to be "python," and everything else needs to be launched with a suffix (e.g., python26.exe). This is usually put earlier on the PATH so that it gets picked up first. For example, right now I have 2.6, 2.7, 3.2, jython, and pypy all installed, and I have "python" pointing to 2.7.

But no Python I am aware of has a suffixed version (python26.exe). Renaming/copying is (in my view) a far more invasive change than simply modifying PATH (and it doesn't help the whole nose/regetron situation either).

Serious question: Given a brand new PC, if you were installing Python 2.7, 3.2, 3.3a1, jython, and pypy, what would you do (beyond simply running 5 installers) to get your environment set up the way you want?

For me, I'd

  1. Install the Python launcher (only until 3.3 includes it)
  2. Edit py.ini to tailor py.exe to my preferred defaults for Python and Python3.
  3. Install my powershell module which allows me to switch which Python is on PATH

Done. (That doesn't cater for pypy or jython, as I don't use them. But I'd probably use a couple of aliases for the rare uses I'd make of them)

 I'd be curious as to how much PEP 397's py.exe would have helped  those people. But yes, it's an issue. Although someone at some point  will have to introduce those beginners to the question of Python 2 vs  Python 3, and PATH pain will hit them then, anyway. I would imagine that it would help steps 1 and 2, but 3 and 4 would be problematic (how can you pip install something using py?) unless you were in a virtualenv, and then (unless py respected the virtualenv) the whole thing would be problematic, because there wouldn't be one clear way to do it.

There isn't one clear way right now. And adding one particular version to PATH only helps if you only have one version.

My current preference is as follows:

  1. If you only ever have one Python on your machine, add it (and its scripts dir) to PATH and be done with it. Unfortunately, we're in the throes of the Python 2-3 transition, and not many people can manage with the one-Python restriction (I certainly can't). Also the Python installer can't detect if that's what you want.
  2. Otherwise, use virtualenvs for anything that isn't being packaged up as a standalone environment. Activate as needed.
  3. To access your system python(s) use py.exe with a version flag if needed. Never (or nearly never) install packages in the system Python.
  4. To run scripts, use #! lines and the py.exe association (and set PATHEXT if you want) to associate the precise Python you want with the script.

I have to say, I've recently discovered virtualenv, so the above is the opinion of a newly-converted zealot - so take with a pinch of salt :-)

Paul.



More information about the Python-Dev mailing list