5

I am using VS Code on Windows 10 with the Windows Linux Subsystem & Ubuntu 18.04.

What I am attempting to do is use VS Code as a python development environment with bash as its terminal and the python3 interpreter installed on the Ubuntu system as its default python executable.

In my User configuration I have:

"terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe"

set, and under Ubuntu python3 is installed and python is an alias to it.

When I attempt to execute a python file I get the following error:

/usr/bin/python3: can't open file 'c:/Users/R ... /test.py': [Errno 2] No such file or directory

My sense is I need to get VS Code passing the path relative to the Linux Subsystem rather than to Windows C:\ to the interpreter. How can I do this?

1
  • 2
    Use /mnt/c/Windows instead of C:\Windows. Commented Jul 31, 2018 at 18:49

4 Answers 4

3

While there does not appear to be official support in Visual Studio Code for Windows, the plugin "Code Runner" with the runInTerminal setting fixes this problem.

It adds a "Run Code" (Alt-Ctrl-N) to the right-click window of an open editor.

If you set the User setting:

"code-runner.runInTerminal": true

And then run the code, it passes the correct filename to the default executable for your terminal environment.

Sign up to request clarification or add additional context in comments.

1 Comment

I needed to leave "code-runner.runInTerminal" unchecked (false) then it worked
2

Linux is case-sensitive, Windows is not. You have "c:" and "C:" in your script. Maybe check for any other discrepancies you might have?

Comments

2

WSL is not officially supported by the Python extension yet. See this issue to track the status for adding support.

Comments

0

Try to install the extension Remote Development extension pack, maybe can fix your problem. Because it will simulate like the vscode is running in the WSl.

https://code.visualstudio.com/docs/remote/wsl#_installation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.