You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a problem at the time of running a Python script using VS Code connected to WSL. If I save the Python script called 'test' as 'test', and then I run the script inside VS Code selecting a conda environment installed on WSL, it will run correctly. But if I save the script as 'test.py', explicitly indicating that it is a Python file, when I run it on VS Code, the terminal will throw "[Errno 2] No such file or directory". This is because the filepath VS Code builds to run the script involves the ' : ' (colon character) in the 'c' folder (disk C of windows). It shoudln't happen beacause WSL interprets the disk C as 'c' not as 'c:', driving to an incorrect path at script run time. Is there a way out of this problem? Or is it a bug that must be fixed?
VS Code version: Code 1.95.2 (e8653663e8840adaf45af01eab5c627a5af81807, 2024-11-07T11:07:22.054Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2
@Santiq22 Can you share more details on how you are running? are you using the run in terminal command from the UI? would it be possible to share the logs from Output > Python?
Sure! I'm not using the terminal command from the UI. Instead, I use the 'Run Python File' button:
And it seems there are no logs associated with this problem. At least in the Outputs window that appears in the panel, there are no logs.
I tried another experiment and, if I run on a terminal the command python3 test.py it works perfectly well. But whatever the current working directory when I am in the VS Code terminal, if I click 'Run Python File', it will give me the same problem. This is the Python file in question:
import os
import platform
print(os.getcwd())
print("=================")
print(os.path.dirname(__file__))
print("===============")
print(os.path.realpath(os.path.dirname(__file__)))
When I run it typing python3 test.py on a terminal it works and gives back:
But if I try running it using the 'Run Python File' button, the terminal shows me the following message:
/home/user_name/anaconda3/envs/env-ml/bin/python c:/Programacion/DM/rar-sagittarius-stream/Source/sagittarius/test.py
/home/user_name/anaconda3/envs/env-ml/bin/python: can't open file '/mnt/c/Programacion/DM/rar-sagittarius-stream/Source/sagittarius/c:/Programacion/DM/rar-sagittarius-stream/Source/sagittarius/test.py': [Errno 2] No such file or directory
Type: Bug
There is a problem at the time of running a Python script using VS Code connected to WSL. If I save the Python script called 'test' as 'test', and then I run the script inside VS Code selecting a conda environment installed on WSL, it will run correctly. But if I save the script as 'test.py', explicitly indicating that it is a Python file, when I run it on VS Code, the terminal will throw "[Errno 2] No such file or directory". This is because the filepath VS Code builds to run the script involves the ' : ' (colon character) in the 'c' folder (disk C of windows). It shoudln't happen beacause WSL interprets the disk C as 'c' not as 'c:', driving to an incorrect path at script run time. Is there a way out of this problem? Or is it a bug that must be fixed?
VS Code version: Code 1.95.2 (e8653663e8840adaf45af01eab5c627a5af81807, 2024-11-07T11:07:22.054Z)
OS version: Windows_NT x64 10.0.19045
Modes:
Remote OS version: Linux x64 5.15.153.1-microsoft-standard-WSL2
Extensions (16)
A/B Experiments
The text was updated successfully, but these errors were encountered: