Wikipedia:Reference desk/Archives/Computing/2018 June 1

noinclude>

Computing desk
< May 31 << May | June | Jul >> June 2 >
Welcome to the Wikipedia Computing Reference Desk Archives
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages.


June 1 edit

Two programs having the same name in Windows edit

I've got two versions of the Python interpreter (2.4 and 3.6). Both are called "python" but are in different directories. To execute a script (just a text file) with Python 3.6 I go: right-click the script, "Open with...", "Choose default program", "Browse", get to Python 3.6 and click "Open". But the script gets executed with Python 2.4. Now if I rename the Python 3.6 executable to "python36" then the script gets executed with Python 3.6 as I want. Why? Does anyone understand what's going on? Thanks. Basemetal 13:33, 1 June 2018 (UTC)[reply]

You should search the internet for how to run two versions of Python simultaneously. Ruslik_Zero 19:43, 2 June 2018 (UTC)[reply]
Install the version you'll really use as the last one. It seems to be a problem in your PATH. You probably have PATH=c:\python\2.4;c:\python\3.6. Windows picks the first python it finds. --Doroletho (talk) 00:00, 3 June 2018 (UTC)[reply]
What you say is no doubt true but is still no explanation of what's going on in this case, because, rememeber, I said I use "browse" and then explicitly open the version I want and Windows still manages to pick the other one. Your advice to just ditch one Python version is good except I can't for the moment as one version is used by GNUSolfège and the other is the one I use. Once I can get rid of GNUSolfège, which I only have in order to find out how to access my sound module from Python, then "uninstalling" GNUSolfège will automatically get rid of that version of Python. I do for the moment get by with the workaround of renaming one of the two Python executables, but I do find the question itself ("theoretically") interesting so I was curious. Basemetal 15:47, 3 June 2018 (UTC)[reply]
  • I have no serious idea what causes the described behaviour. I can speculate that when you do "open foo with /some/dir/stuff.exe", what really happens behind the scenes is cd /some/dir; stuff foo and then the stuff is taken from the path rather than from the current directory, but that would mean (1) that the path comes before the current dir in the priority order and (2) that "open with..." does not use the natural implementation /some/dir/stuff foo, both of which seem improbable.
However, instead of manually browsing to the Python version you want... The "good" solution is a shebang line at the start of the script to tell the OS which of the Python versions to use. That is not available on Windows, but there are ways to make it work (assuming you have admin rights, at least). TigraanClick here to contact me 07:45, 5 June 2018 (UTC)[reply]
You probably launch not a python executable by a python launcher ('py'). It can launch any version of python if configured appropriately. See this. Ruslik_Zero 09:19, 6 June 2018 (UTC)[reply]
Not clear who you're replying here but your link is useful, so thanks. Are you an experienced Python programmer? Basemetal 16:33, 6 June 2018 (UTC)[reply]
  • And by the way, thanks also to the other respondents namely Doroletho and especially Tigraan. Basemetal 16:35, 6 June 2018 (UTC)[reply]