This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Windows 7, script exec not working without explicit cal of python.exe
Type: behavior Stage: resolved
Components: Windows Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, ned.deily, tsunwell
Priority: normal Keywords:

Created on 2013-09-20 09:28 by tsunwell, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg198136 - (view) Author: Thierry Seunevel (tsunwell) Date: 2013-09-20 09:28
Executing a script from the command prompt works if Python.exe called explicitly, doesn't work if script name only.
Example :
python.exe script.py is ok
script.py gives the following :
Traceback (most recent call last):
  File "D:\soft\python\lib\site.py", line 548, in <module>
    main()
  File "D:\soft\python\lib\site.py", line 530, in main
    known_paths = addusersitepackages(known_paths)
  File "D:\soft\python\lib\site.py", line 266, in addusersitepackages
    user_site = getusersitepackages()
  File "D:\soft\python\lib\site.py", line 241, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "D:\soft\python\lib\site.py", line 231, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "D:\soft\python\lib\sysconfig.py", line 516, in get_config_var
    return get_config_vars().get(name)
  File "D:\soft\python\lib\sysconfig.py", line 449, in get_config_vars
    import re
  File "D:\soft\python\lib\re.py", line 105, in <module>
    import sre_compile
  File "D:\soft\python\lib\sre_compile.py", line 14, in <module>
    import sre_parse
  File "D:\soft\python\lib\sre_parse.py", line 17, in <module>
    from sre_constants import *
  File "D:\soft\python\lib\sre_constants.py", line 18, in <module>
    from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
Association of py extension to the python.exe is ok, Path contains the path for python directory (and also to \lib) and is the first dir in path.
Why is there a difference between the 2 invocations as they are calling the same exe?
msg198151 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2013-09-20 17:00
Can you print out sys.executable and sys.path in both cases, and post the results here?
msg198153 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2013-09-20 17:10
You may have a mismatch with two different versions of Python 2.7 installed.  Issue18050 documents the basic problem: a change introduced in Python 2.7.4 causes problems if a pre-2.7.4 interpreter executable is launched with a 2.7.4 or later Python standard library.
msg198190 - (view) Author: Thierry Seunevel (tsunwell) Date: 2013-09-21 09:38
Many thanks for your answers.
printing the sys.path gave me this output (parsed with newlines)
'', 'D:\\soft\\python\\lib', 
'D:\\Thierry\\python\\d\\thierry\\python', <---- mispelled
'C:\\Windows\\system32\\python27.zip',
'd:\\soft\\python\\DLLs', 
'd:\\soft\\python\\lib\\plat-win', 
'd:\\soft\\python\\lib\\lib-tk', 
'd:\\soft\\python', 
'd:\\soft\\python\\lib\\site-packages'

I corrected the PATH and PYTHONPATH environment variables and now sys.path is 
'', 'd:\\thierry\\python', 
'C:\\Windows\\system32\\python27.zip', 
'd:\\soft\\python\\DLLs', 
'd:\\soft\\python\\lib', 
'd:\\soft\\python\\lib\\plat-win', 
'd:\\soft\\python\\lib\\lib-tk', 
'd:\\soft\\python', 
'd:\\soft\\python\\lib\\site-packages'

And it works !
msg198193 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2013-09-21 11:24
Glad to see it's working.
History
Date User Action Args
2022-04-11 14:57:51adminsetgithub: 63256
2013-09-21 11:24:54eric.smithsetstatus: open -> closed
resolution: fixed -> not a bug
messages: + msg198193

stage: resolved
2013-09-21 09:38:21tsunwellsetresolution: fixed
messages: + msg198190
2013-09-20 17:10:40ned.deilysetnosy: + ned.deily
messages: + msg198153
2013-09-20 17:00:41eric.smithsetnosy: + eric.smith
messages: + msg198151
2013-09-20 09:28:48tsunwellcreate