0

I have a script called "submit.py" and it begins with "#!/usr/bin/env python.exe" which works if I'm inside the directory containing "submit.py". I can run "./submit.py" and the script runs properly. I decided to add the directory containing "submit.py" to my PATH environment variable so I can run "submit.py" from any directory.

However, I cannot run "submit.py" from any directory. The error I get is:

D:\Program Files\Python36\python.exe: can't open file '/mnt/d/Program Files/kattisTools/submitToKattis': [Errno 2] No such file or directory

I believe the error has to do with the differences in how Windows Python expects a path to be and how WSL handles paths. What I mean is python.exe should be looking for "D:\Program Files\kattisTools\submitToKattis" but WSL is feeding it "/mnt/d/Program Files/kattisTools/submitToKattis"

I also believe that "./submit.py" works when I'm inside the directory containing submit.py because the '.' operator is handled differently in WSL that feeds the real Windows path to Windows Python.

I was hoping there's a remedy so that I can run "submit.py" from any directory with it relying on Windows Python?

06/26/2018 Update: I have looked into Shared Environment Variables between WSL and Windows, and particularly the '/w' flag. I haven't gotten this to work the way I wanted yet but it might be something?

Garfield Tong
  • 408
  • 4
  • 12
  • What is the contents of PATH? Which Windows version are you on? – AcK Jun 24 '18 at 08:18
  • So I set the PATH variable via native Windows, so It's "D:\Program Files\kattisTools". That gets translated properly when WSL generates the PATH variable and pulls from Windows PATH – Garfield Tong Jun 24 '18 at 21:44

1 Answers1

0

did you get this to work by now? Having the same issue here when calling a python script with a pipenv virtual environment (windows based python.exe) from within the wsl :(

You are completely right.... Calling the script directly from its folder it looks like that: C:\scripts\.venv\Scripts\python.exe ./test.py and it works

while it looks like that (and does not work) if it is called from another folder: C:\scripts\.venv\Scripts\python.exe /mnt/c/scripts/test.py

sfx2k
  • 73
  • 4
  • I haven't tested recently honestly. You could have intermediate scripts that do translating for you, `wsl` now comes with `wslpath` which you can use to translate between wsl paths and Windows paths. Have you tested recently? Because I think I was testing Firefox.exe the other day and successfully had seamless interoperability, WSL is developing extraordinarily fast so features and fixes can be added even as we speak. – Garfield Tong Nov 14 '19 at 20:43
  • Unfortunately I am (or rather my company...) still on build 16299 - no wslpath... :( – sfx2k Nov 15 '19 at 15:29
  • Oh! Well you could always just grab `wslpath` from source right? That would be this: https://github.com/laurent22/wslpath – Garfield Tong Nov 15 '19 at 15:34
  • Thanks! I'll give it a try – sfx2k Nov 16 '19 at 23:26