Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No such file or directory" when using Windows Linux Subsystem bash with VS Code

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?

like image 629
redcartel Avatar asked Jul 31 '18 18:07

redcartel


People also ask

How do I fix No such file or directory in Linux?

First, make sure you execute the program with the correct path. If you make a typo on the directory or file name, you will get this error or give the wrong path. If you are executing the file with a relative path ( ../../file ), try executing with the absolute path ( /path/to/file ) instead.

How do I enable VS Code in WSL?

From VS Code Start VS Code. Press F1, select Remote-WSL: New Window for the default distro or Remote-WSL: New Window using Distro for a specific distro. Use the File menu to open your folder.

Why am I getting no such file or directory?

log No such file or directory” the problem is most likely on the client side. In most cases, this simply indicates that the file or folder specified was a top-level item selected in the backup schedule and it did not exist at the time the backup ran.

How do I fix the Windows Subsystem for Linux optional component is not enabled?

The Windows Subsystem for Linux optional component is not enabled: Open Control Panel -> Programs and Features -> Turn Windows Feature on or off -> Check Windows Subsystem for Linux or using the PowerShell cmdlet mentioned at the beginning of this article.


2 Answers

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.

like image 115
redcartel Avatar answered Nov 15 '22 00:11

redcartel


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

like image 25
ColemanTO Avatar answered Nov 14 '22 23:11

ColemanTO