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?

4

1 回答 1

0

你现在让它工作了吗?从wsl中调用带有pipenv虚拟环境(基于windows的python.exe)的python脚本时遇到同样的问题:(

你是完全正确的......直接从它的文件夹中调用脚本它看起来像这样: C:\scripts\.venv\Scripts\python.exe ./test.py 并且它可以工作

如果从另一个文件夹调用它看起来像那样(并且不起作用): C:\scripts\.venv\Scripts\python.exe /mnt/c/scripts/test.py

于 2019-11-14T07:13:35.943 回答