python - 使用带有 VS Code 的 Windows Linux 子系统 bash 时出现“没有这样的文件或目录”
问题描述
我在带有 Windows Linux 子系统和 Ubuntu 18.04 的 Windows 10 上使用 VS Code。
我正在尝试做的是使用 VS Code 作为 python 开发环境,以 bash 作为其终端,并将安装在 Ubuntu 系统上的 python3 解释器作为其默认的 python 可执行文件。
在我的用户配置中,我有:
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"
设置,并在 Ubuntu 下安装 python3 并且python
是它的别名。
当我尝试执行 python 文件时,出现以下错误:
/usr/bin/python3: can't open file 'c:/Users/R ... /test.py': [Errno 2] No such file or directory
我的感觉是我需要让 VS Code 将相对于 Linux 子系统而不是 Windows C:\ 的路径传递给解释器。我怎样才能做到这一点?
解决方案
虽然 Visual Studio Code for Windows 似乎没有官方支持,但带有 runInTerminal 设置的插件“Code Runner”解决了这个问题。
它将“运行代码”(Alt-Ctrl-N)添加到打开的编辑器的右键单击窗口中。
如果您设置用户设置:
“code-runner.runInTerminal”:真
然后运行代码,它将正确的文件名传递给终端环境的默认可执行文件。
推荐阅读
- context-free-grammar - 模糊的 CFG 是否有可能转换为 CNF 并变得明确?
- java - API针对不同场景返回不同的对象类型
- nodes - 节点的 Networkx 和 matplotlib 颜色图;不同网络的相同地图
- html - 是否可以将多个视频加载到 HTML 5 视频播放器中并让它们一个接一个地按顺序播放?
- javascript - 如何停止跟踪 AdRoll Pixel?
- python - 在python中完成系列(数据框)
- algorithm - 查找每列具有不同值的子集
- laravel - 如何使用 Laravel 确定用户在线状态/离线状态?
- domain-driven-design - 具有重要不变量的潜在大型集合的 DDD 聚合
- javascript - 如果 React JSX 中的条件,则从 json 数组 wrt 中删除数组