2

After installing the WSL I have two python installations on my PC, the Windows one and the one in the WSL. The developers state here that you "can invoke Windows binaries directly from the WSL command line," however, when I try to invoke the python.exe file I get the following odd behavior:

myprompt$ python.exe
1
2 
print("test")
print "test"
    File "<stdin>", line 4
        print "test"
                   ^
SyntaxError: Missing parentheses in call to 'print' 
myprompt$

Whereas if the interactive interpreter was running, I'd get:

myprompt$ python.exe
>>>1
1
>>>2 
2
print("test")
test
print "test"
    File "<stdin>", line 1
        print "test"
                   ^
SyntaxError: Missing parentheses in call to 'print' 
myprompt$

Its like the interpreter is running, but its not giving me a prompt, and it exits at the first error. Interestingly, if I navigate to the same directory and run python.exe from a windows command prompt, everything works fine.

P.S.: I found the location of the Windows Python install by running the sys.executable command in Python.

Evan Rosica
  • 1,182
  • 1
  • 12
  • 22
  • Please do not post graphics unless the issue specifically needs it, copy and paste the text instead. Having said that, this one looks fairly straightforward, you are trying to run old python 2 code on python 3. – cdarke Dec 19 '17 at 09:28
  • The question isn't why the error is popping up, the question is where did the >>> prompt go? Why did I get no output from the properly formatted print("test") ?? Shouldn't typing python.exe start up the interactive interpreter? – Evan Rosica Dec 19 '17 at 09:32
  • 2
    Looks like your executable is getting a parameter to start a script. And when the script is finished, you don´t get the prompt anymore. – creyD Dec 19 '17 at 09:40
  • @creyD thats exactly what it seems like, but why should calling python.exe from within the WSL and the powershell generate different behavior (and how do I fix it)? – Evan Rosica Dec 19 '17 at 09:43
  • Looks to me like a bug or a huge misconfiguration within the subsytem... I tried it on my computer and it worked as it should... – creyD Dec 19 '17 at 09:55
  • weird ... I tried reinstalling the entire subsystem and got the same result. Interestingly, I tried writing a script (myfile.py) which printed one line of text, and running it by: python.exe myfile.py. That worked fine. – Evan Rosica Dec 19 '17 at 09:58
  • Update: running python.exe -i starts python in interactive mode. So I know a workaround. I'm still curious why its necessary though. I was lucky to find this related issue: https://stackoverflow.com/questions/32454589/git-2-5-1s-bash-console-doesnt-open-python-interpreter. – Evan Rosica Dec 19 '17 at 10:05
  • Try typing *python3* just as it is. Maybe it is a problem with the .exe wich is not really compatible with linux... – creyD Dec 19 '17 at 10:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/161514/discussion-between-evan-rosica-and-creyd). – Evan Rosica Dec 19 '17 at 10:11

1 Answers1

1

Use the -i option to bring up the interactive interpreter. So running

python.exe -i

will start the windows version of python interactively from the WSL.

Evan Rosica
  • 1,182
  • 1
  • 12
  • 22
  • So the `-i` made it interactive as desired, but I was running into other weird issues.I also needed to include `-u` (unbuffered) or it wouldn't print immediately and would have other weird behavior. I also found that I couldn't run python files using Windows python that were in files that were only part of wsl and not in the normal file system of windows. – Robert Hickman Sep 13 '18 at 16:52