python - Path handling error calling Windows Python from within WSL
问题描述
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?
解决方案
你现在让它工作了吗?从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
推荐阅读
- java - Android PlaceAutocompleteFragment 自动关闭
- sql-server - 在使用 INSERT 触发器后向 INSERTED 表添加值
- python-3.x - 如何在带有 asyncio 的 pyzmq 中使用 REQ 和 REP?
- javascript - 过滤值列表
- ruby - 使 Ruby 对象响应双 splat 运算符**
- jquery - 如何在j查询数据表中的列标题旁边显示一个圆圈
- javascript - unshift 方法不断在选择器中推送新对象
- apache-kafka - 哪个 ZooKeeper 与 Apache Kafka 一起使用?
- c# - hackerrank 中的 ArrayIndexOutOfBounds 异常
- sql - 重新排序 SQL 数据(足球数据)