Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong path when running .py script in WSL #24407

Open
Santiq22 opened this issue Nov 8, 2024 · 2 comments
Open

Wrong path when running .py script in WSL #24407

Santiq22 opened this issue Nov 8, 2024 · 2 comments
Assignees
Labels
triage-needed Needs assignment to the proper sub-team

Comments

@Santiq22
Copy link

Santiq22 commented Nov 8, 2024

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)
Extension Author (truncated) Version
vsc-python-indent Kev 1.18.0
jupyter-keymap ms- 1.1.2
remote-wsl ms- 0.88.5
jinja who 0.0.8
python-environment-manager don 1.2.4
linter-gfortran for 3.2.0
debugpy ms- 2024.12.0
python ms- 2024.18.0
vscode-pylance ms- 2024.11.1
jupyter ms- 2024.10.0
jupyter-keymap ms- 1.1.2
jupyter-renderers ms- 1.0.21
vscode-jupyter-cell-tags ms- 0.1.9
vscode-jupyter-slideshow ms- 0.1.6
cpptools ms- 1.22.11
autodocstring njp 0.6.1
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805cf:30301675
binariesv615:30325510
vsaa593:30376534
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
pythongtdpath:30769146
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
f3je6385:31013174
dvdeprecation:31068756
dwnewjupytercf:31046870
2f103344:31071589
impr_priority:31102340
nativerepl2:31139839
refactort:31108082
pythonrstrctxt:31112756
cf971741:31144450
iacca1:31171482
notype1:31157159
5fd0e150:31155592
dwcopilot:31170013

@vs-code-engineering vs-code-engineering bot added the triage-needed Needs assignment to the proper sub-team label Nov 8, 2024
@lszomoru lszomoru transferred this issue from microsoft/vscode Nov 8, 2024
@lszomoru lszomoru removed their assignment Nov 8, 2024
@karthiknadig
Copy link
Member

@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?

@github-actions github-actions bot added the info-needed Issue requires more information from poster label Nov 11, 2024
@karthiknadig karthiknadig self-assigned this Nov 11, 2024
@Santiq22
Copy link
Author

Sure! I'm not using the terminal command from the UI. Instead, I use the 'Run Python File' button:

Image
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:

/mnt/c/Programacion/DM/rar-sagittarius-stream/Source/sagittarius
=================
/mnt/c/Programacion/DM/rar-sagittarius-stream/Source/sagittarius
===============
/mnt/c/Programacion/DM/rar-sagittarius-stream/Source/sagittarius

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

@github-actions github-actions bot removed the info-needed Issue requires more information from poster label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage-needed Needs assignment to the proper sub-team
Projects
None yet
Development

No branches or pull requests

3 participants