Windows temporary file association for Python files
I wonder if it will make the life easier if Python was installed with .py association to "%PYTHON_HOME%\python.exe" "%1" %* It will remove the need to run .py scripts in virtualenv with explicit 'python' prefix. Example how it doesn't work right now E:\virtenv32\Scripts>echo import sys; print(sys.version) > test.py E:\virtenv32\Scripts>test.py 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] E:\virtenv32\Scripts>python test.py 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] If Python file association was specified with "%PYTHON_HOME%\python.exe" "%1" %* then virtualenv could override this variable when setting the environment to set correct executable for .py files. -- anatoly t.
On 22 October 2012 11:51, anatoly techtonik <techtonik@gmail.com> wrote:
I wonder if it will make the life easier if Python was installed with .py association to "%PYTHON_HOME%\python.exe" "%1" %* It will remove the need to run .py scripts in virtualenv with explicit 'python' prefix.
In Python 3.3 and later, the "py.exe" launcher is installed, and this is the association for ".py" files by default. It looks at the #! line of .py files, so you can run a specific Python interpreter by giving its full path. You can also specify (for example) "python3" or "python3.2" to run a specific Python version. A less known fact is that you can define custom commands for py.exe in a py.ini file. So you can have [commands] vpy=python in your py.ini, and then start your script with #!vpy to make it use the currently active Python (whichever is on %PATH%). Hope that helps, Paul
On Mon, Oct 22, 2012 at 2:44 PM, Paul Moore <p.f.moore@gmail.com> wrote:
On 22 October 2012 11:51, anatoly techtonik <techtonik@gmail.com> wrote:
I wonder if it will make the life easier if Python was installed with .py association to "%PYTHON_HOME%\python.exe" "%1" %* It will remove the need to run .py scripts in virtualenv with explicit 'python' prefix.
In Python 3.3 and later, the "py.exe" launcher is installed, and this is the association for ".py" files by default. It looks at the #! line of .py files, so you can run a specific Python interpreter by giving its full path. You can also specify (for example) "python3" or "python3.2" to run a specific Python version.
Yes, I've noticed that this nasty launcher gets in the way. So, do you propose to edit source files every time I need to test them with a new version of Python? My original user story: I want to execute scripts in virtual environment (i.e. with Python installed for this virtual environment) without 'python' prefix. Here is another one. Currently Sphinx doesn't install with Python 3.2 and with Python 3.3 [1]. Normally I'd create 3 environments to troubleshoot it and I can not modify all Sphinx files to point to the correct interpreter to just execute 'setup.py install'. A solution would be to teach launcher to honor PYTHON_PATH variable if it is set (please don't confuse it with PYTHONPATH which purpose is still unclear on Windows). 1. https://bitbucket.org/birkenfeld/sphinx/issue/1022/doesnt-install-with-pytho...
On 22/10/2012 13:42, anatoly techtonik wrote:
On Mon, Oct 22, 2012 at 2:44 PM, Paul Moore <p.f.moore@gmail.com> wrote:
On 22 October 2012 11:51, anatoly techtonik <techtonik@gmail.com> wrote:
I wonder if it will make the life easier if Python was installed with .py association to "%PYTHON_HOME%\python.exe" "%1" %* It will remove the need to run .py scripts in virtualenv with explicit 'python' prefix.
In Python 3.3 and later, the "py.exe" launcher is installed, and this is the association for ".py" files by default. It looks at the #! line of .py files, so you can run a specific Python interpreter by giving its full path. You can also specify (for example) "python3" or "python3.2" to run a specific Python version.
Yes, I've noticed that this nasty launcher gets in the way. So, do you propose to edit source files every time I need to test them with a new version of Python? My original user story:
I see nothing nasty in the launcher, rather it's extremely useful. You don't have to edit your scripts. Just use py -3.2, py -2 or whatever to run the script, the launcher will work out which version to run for you if you're not specific.
I want to execute scripts in virtual environment (i.e. with Python installed for this virtual environment) without 'python' prefix.
Here is another one. Currently Sphinx doesn't install with Python 3.2 and with Python 3.3 [1]. Normally I'd create 3 environments to troubleshoot it and I can not modify all Sphinx files to point to the correct interpreter to just execute 'setup.py install'.
Please try running your scripts with the mechanism I've given above and report back what happens, hopefully success :)
A solution would be to teach launcher to honor PYTHON_PATH variable if it is set (please don't confuse it with PYTHONPATH which purpose is still unclear on Windows).
What is PYTHON_PATH? IIRC I was told years ago *NOT* to use PYTHONPATH on Windows so its purpose to me isn't unclear, it's completely baffling.
1. https://bitbucket.org/birkenfeld/sphinx/issue/1022/doesnt-install-with-pytho...
-- Cheers. Mark Lawrence.
A solution would be to teach launcher to honor PYTHON_PATH variable if it is set (please don't confuse it with PYTHONPATH which purpose is still unclear on Windows). What are you talking about? PYTHON_PATH doesn't appear in the CPython
On 10/22/2012 8:42 AM, anatoly techtonik wrote: sources at all. PYTHONPATH has the same purpose on Windows that it has anywhere: a list of directories to prefix to sys.path to find modules when importing. --Ned.
On Mon, Oct 22, 2012 at 6:51 AM, anatoly techtonik <techtonik@gmail.com> wrote:
I wonder if it will make the life easier if Python was installed with .py association to "%PYTHON_HOME%\python.exe" "%1" %* It will remove the need to run .py scripts in virtualenv with explicit 'python' prefix.
Example how it doesn't work right now
E:\virtenv32\Scripts>echo import sys; print(sys.version) > test.py
E:\virtenv32\Scripts>test.py 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)]
E:\virtenv32\Scripts>python test.py 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] If Python file association was specified with "%PYTHON_HOME%\python.exe" "%1" %* then virtualenv could override this variable when setting the environment to set correct executable for .py files.
I believe you can solve your problem with the PY_PYTHON environment variable or the user's py.ini file. See section 3.4.4 of the documentation.
On Mon, Oct 22, 2012 at 4:16 PM, Mark Lawrence <breamoreboy@yahoo.co.uk>wrote:
On 22/10/2012 13:42, anatoly techtonik wrote:
On Mon, Oct 22, 2012 at 2:44 PM, Paul Moore <p.f.moore@gmail.com> wrote:
On 22 October 2012 11:51, anatoly techtonik <techtonik@gmail.com> wrote:
I wonder if it will make the life easier if Python was installed with .py association to "%PYTHON_HOME%\python.exe" "%1" %* It will remove the need to run .py scripts in virtualenv with explicit 'python' prefix.
In Python 3.3 and later, the "py.exe" launcher is installed, and this is the association for ".py" files by default. It looks at the #! line of .py files, so you can run a specific Python interpreter by giving its full path. You can also specify (for example) "python3" or "python3.2" to run a specific Python version.
Yes, I've noticed that this nasty launcher gets in the way. So, do you propose to edit source files every time I need to test them with a new version of Python? My original user story:
I see nothing nasty in the launcher, rather it's extremely useful. You don't have to edit your scripts. Just use py -3.2, py -2 or whatever to run the script, the launcher will work out which version to run for you if you're not specific.
Nice. Didn't know about that.
I want to execute scripts in virtual environment (i.e. with Python
installed for this virtual environment) without 'python' prefix.
Here is another one. Currently Sphinx doesn't install with Python 3.2 and with Python 3.3 [1]. Normally I'd create 3 environments to troubleshoot it and I can not modify all Sphinx files to point to the correct interpreter to just execute 'setup.py install'.
Please try running your scripts with the mechanism I've given above and report back what happens, hopefully success :)
Not really. It doesn't work with virtualenv at all. E:\p>cat version.py import sys print(sys.version) E:\p>python version.py 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] E:\p>32\Scripts\activate (32) E:\p>python version.py 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] (32) E:\p>version.py 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] (32) E:\p>py version.py 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]
A solution would be to teach launcher to honor PYTHON_PATH variable if it is set (please don't confuse it with PYTHONPATH which purpose is still unclear on Windows).
What is PYTHON_PATH? IIRC I was told years ago *NOT* to use PYTHONPATH on Windows so its purpose to me isn't unclear, it's completely baffling.
Sorry, it was PYTHON_HOME - variable from .py association I proposed, i.e. "%PYTHON_HOME%\python.exe" "%1" %* If association is made in this way, then virtualenv could override PYTHON_HOME and get `version.py` command execute with it's own interpreter. Now with py.exe it looks a better idea to have PYTHONBIN environment variable and the association set to "%PYTHONBIN%" "%1" %*. This way virtualenv can easily override it during activation to make .py files executable with whatever Python (or PyPy) it has configured.
participants (5)
-
anatoly techtonik
-
David Robinow
-
Mark Lawrence
-
Ned Batchelder
-
Paul Moore