New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sys.argv contains only scriptname #52184
Comments
I am running Python 2.6.4 on Windows Vista and when I try to get any command line arguments via sys.argv, it only contains sys.argv[0], but nothing else. Even if I supply several parameters. The only third-parts modules I am using are Pygame, but even before Pygame imports, there is nothing in sys.argv. I've tried creating a shortcut with the args in it, but it still doesn't work. |
How do you supply parameters to your script? From a command prompt, type: |
Actually, I was playing around with it and I found that using the "python" command before it does work. |
Sorry for a double-comment, but I thought of posting this after I already submitted the last one and I found no edit button. Here's some output: "Microsoft Windows [Version 6.0.6001] (Sorry it's so long, I cut out the blank lines as it is) |
I'm getting something like this on Windows 7: C:\>assoc .py C:\>ftype Python.File C:\>args.py 1 2 3 C:\>\python31\py31 args.py 1 2 |
I've read on a random forum somewhere that % need to be doubled on Windows 7. |
No joy :( I tried putting double-quotes around %%*, that didn't work either. Tried single-quotes too, just in case it works like a Bourne-type shell. BTW I forgot to set 3.1 on my earlier message. That business about having to double the % rings a faint bell from the old MS-DOS days, though. Can't remember. Something about, it will interpret it once, so you have to make sure it comes out the way you want after it does that. (Which is old hat to anyone who does much programming in a Unix shell, but it was new to me back then.) I remember it was rather difficult to get it right. |
Closed bpo-8984 as a duplicate of this; merging nosy lists. Tom, did you ever find a solution to this problem? |
Here's a link to a similar discussion about Perl on Windows: http://community.activestate.com/forum-topic/problem-passing-arguments |
From various other sites, and from experiments (thanks Eric Smith) it looks like the associations reported by 'assoc' and 'ftype' aren't necessarily the associations that are actually being used. Sworddragon: can you get any useful information out of the Windows registry (e.g., using regedit, searching for Python.File, and looking under shell\open\command), or by setting file associations through the Control Panel? I don't know enough about Python on Windows to know whether there's any hope that this is a problem that can be solved at the Python end, but I'd guess not. |
I agree with Mark: there's probably nothing Python can do about this. It's almost certainly an error with how Python is being invoked. |
That being said, it would be interesting to see what the registry key HKEY_CLASSES_ROOT\Python.File\shell\open\command contains. |
This registry key contains "E:\Python31\python.exe" "%1" %*. I have too 2 python versions installed and manually associated the .py files to Python 3. |
I have set now the key to "E:\Python31\python.exe" "%%1" %%* and it works. So Windows XP need double % too. The installer of the next version should consider this. |
I made a mistake in the last post. After I have set the value, Python 2 was active and I forgot to set it to Python 3 back. This solution doesn't work. Well, I can't edit or delete the post. |
Now I found the real solution (and don't forgot to set it to Python 3 back). I have searched in the registry for python.exe to look how Python 2 is doing this. I sawed a key that looks dissimilar to the others before. It is the key HKEY_USERS\S-1-5-21-1078081533-682003330-1801674531-1003\Software\Classes\Applications\python.exe\shell\open\command which have the Standard value of "E:\Python31\python.exe" "%1". I set it to "E:\Python31\python.exe" "%1" %* and it worked. |
So the real question is is: how does that key get that invalid value? I can't reproduce the problem. I believe that key you mention is an alias for HKEY_CURRENT_USER\Software\Classes\Applications\python.exe\shell\open\command, which doesn't exist on my XP machine. |
I have now uninstalled Python 2 and 3 and installed them new. First Python 2 with only register extension and compile files to bytecode. After this I have made the same with Python 3. In the "Open with" menu was now "python" registered which was Python 3 (sys.version[0] from a testscript telled it me). Until this point the arguments were accepted. After this I have added the python.exe from Python 2 to the "Open with" menu. This was the point where the key got invalid. Now Python 3 is working correctly but not Python 2. Well, I can manually use now the workarround to fix it but maybe the problem can be solved with this information. |
The problem went away by itself after a while. I suspect a Windows update. |
I found this page while encountering the same problem (only one argument, the scriptname, being passed in from the command line), and wanted to post the following workaround. I'm running Vista and using Python 2.6. Before finding this fix: |
Encountered the same issue with 3.1.2 and 3.1.3 64bit on Win7 64bit. I was able to fix it in registry but did so many changes at once that I'm not able to reproduce (was really annoyed after trying to fix it for half a day...). Anyway, sending my observations:
If anyone else can confirm that deleting of python.exe and pythonw.exe from HKCR itself corrects the issue, I think the installation program can check if these entries exists and offer to delete them. Just for complete picture, it works now even with .py and .pyw in PATHEXT, so calling the scripts without extension. |
I'm sorry, I changed version to 3.3 by mistake. Did not want to do it. |
I had the same problem with another version of python on Windows 7. We are using python 2.4.2 for production and it is installed in D:\Tools\Python. For experimentation purpose, I installed Python 2.7 in the usual location. It broke a few things and I uninstalled both python, and reinstalled only 2.4.2. After that, using python 2.4.2, I got the problem described by this issue. None of my colleagues (who did not install Python 2.7) had the issue. The registry entry HKEY_CLASSES_ROOT\py_auto_file\shell\open\command was reading: D:\Tools\Python\python.exe "%1" It was missing %*. I added it and my issue went away. |
I finally found a solution from a page on StackOverflow. I had modified or added six other keys but only the one above solved the problem. Before the fix: After the fix: In hindsight I should have searched the registry for python paths that didn't have the ending %*. Very briefly, for those unfamiliar with Windows' RegEdit: |
I have v2.7, v3.2, and v3.3 installed on a Win7 64-bit machine and the exact same setup on a Win7 32-bit machine. The 32-bit works OK. The 64-bit machine had this argv problem, too! (I tried installing either Win32/Win64 version, no difference!) Adding %* fixed the argv problem, but I noticed there was one more. The wrong version was called. To sum it up, I had to change only the key from: c:\Python32\Python32.exe "%1" %* to: c:\Python33\Python33.exe "%1" %* or to: c:\windows\py.exe "%1" %* (for auto-detection, both worked) |
I ran into this issue by doing the following steps, though I did not try to reproduce: 1 - install Python 3.4 Then I encountered issues where all .py scripts were opened with Python 2.7. After some unsuccessful attempts I decided to uninstall Python 2.7 4 - remove Python 2.7 At this point, I had to update the file associations because Windows could not find Python 2.7 anymore 5 - update file associations The issue is obviously that in at least a few places in the registry, the ..\shell\open\command has a value of ..\python.exe "%1" In my case it was under all roots: HKEY_CLASSES_ROOT\py_auto_file I corrected only the one under HKEY_USERS by adding %* and it resolved the issue. |
@alecz are you aware of the Python launcher, see https://www.python.org/dev/peps/pep-0397/ and https://docs.python.org/3/using/windows.html#python-launcher-for-windows ? The easiest way to sort out 3.4 would have been to download the msi file and use the repair option. Having said that I've no idea whether or not this issue can be sorted out, or is already sorted in 3.5. @Steve, Zach or Tim, over to you :) |
I am closing this because there is no identifiable issue with the current installers. Initial issues were reported fixed. The most recent issue reported by Alecz was that installing 2.7 after 3.4 caused python files to be opened by 2.7. This is what should happen when 2.7 is installed as the default python (there is an option to select this or not). Questions about using python.org installers or python should be directed elsewhere, such as python-list. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: