Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Python scripts are executed with the wrong path separator in integrated Powershell on Windows #13811

Closed
tsbertalan opened this issue Sep 6, 2020 · 4 comments
Labels
area-terminal feature-request Request for new features or functionality

Comments

@tsbertalan
Copy link

Environment data

  • VS Code version: 1.48.2
  • Extension version (available under the Extensions sidebar): 2020.08.106424
  • OS and version: Windows 10 , 1909, build 18363.1016
  • Python version (& distribution if applicable, e.g. Anaconda): Anaconda, 3.7.7
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: N/A
  • Relevant/affected Python-related VS Code extensions and their versions: N/A
  • Value of the python.languageServer setting: Jedi

Expected behaviour

On Windows, with Powershell as the embedded terminal, the path to the python executable and to the current script being executed should use backslashes.

Actual behaviour

A script command line like this is generated:

(py37) PS C:\Users\tsbertalan\SNIPPED> & C:/Users/tsbertalan/Anaconda3/envs/py37/python.exe "c:/Users/tsbertalan/SNIPPED/SCRIPT.py"

However, invoking workbench.action.debug.start instead generates:

(base) PS C:\Users\tsbertalan\SNIPPED>  & 'C:\Users\tsbertalan\Anaconda3\envs\py37\python.exe' 'c:\Users\tsbertalan\.vscode\extensions\ms-python.python-2020.8.106424\pythonFiles\lib\python\debugpy\launcher' '53300' '--' 'c:\Users\tsbertalan\SNIPPED\SCRIPT.py'

Which was very confusing at first--when I debugged the script, paths which were constructed using os.path.join with os.path.basename(__file__) had homogeneous, all-backslash paths, but when I ran it with python.execInTerminal, the paths were mixed!

Steps to reproduce:

  1. Use "Python: Select Interpreter" to launch a file dialog and locate python.exe in C:\Users\USERNAME\Anaconda3\envs\ENVNAME.
  2. Use python.execInTerminal (the little play button) to launch a script, with terminal.integrated.shell.windows unset (that is, left to its default of C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe).
  3. Witness the forward-slash generated command in the integrated terminal.

I'm currently working on a script that uses os.path.join, os.path.basename, etc., and in particular uses basename(__file__) to get the path of the current script in a cross-platform way. This does intelligently interprets the forward slashes as path separators, and trims off the SCRIPT.py part, leaving a C:/Users... path. But then, subsequent joins with this path have mixed slashes, since join correctly uses backslash as a path separator on windows.

This isn't a problem for my script at the moment, since all file-access code (for instance, these mixed-slash paths are being passed to glob.glob) seems to be intelligently homogenizing the slashes. But it could become a problem in the future.

@tsbertalan tsbertalan added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Sep 6, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 8, 2020
@ericsnowcurrently
Copy link
Member

@tsbertalan, thanks for letting us know about this. We'll take a look and get back to you as soon as possible.

@karthiknadig karthiknadig added investigating We are looking into the cause of the issue and removed triage labels Sep 15, 2020
@ericsnowcurrently ericsnowcurrently added triage and removed investigating We are looking into the cause of the issue labels Sep 21, 2020
@ericsnowcurrently ericsnowcurrently added area-terminal investigating We are looking into the cause of the issue and removed triage labels Oct 26, 2020
@karrtikr karrtikr added triage and removed investigating We are looking into the cause of the issue labels Mar 23, 2021
@karrtikr
Copy link

karrtikr commented Apr 6, 2021

Is this issue still happening with the latest version of the extension?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Apr 6, 2021
@tsbertalan
Copy link
Author

tsbertalan commented Apr 6, 2021

Yes, I'm usually running on Ubuntu these days (or, if on Windows, using the remote feature over SSH), so I don't bump up against this. However, I uninstalled and reinstalled the Python, Jupyter, and Pylance extensions just now (Python extension is now at v2021.3.680753044). I still see all-backslashes when running a script in debug mode, but, in run mode, backslashes in the prompt and forward slashes in the python.exe and BLAH.py path to the right of the prompt.

@karrtikr
Copy link

karrtikr commented Apr 6, 2021

@tsbertalan Thanks for the prompt response. We think the general solution on how to launch scripts should come from VSCode, microsoft/vscode#108550.

I'm converting this to a feature request under Github discussions to see how many users face this issue. My initial gut says that you seem to have a very special case where the way script is launched is important to you, but for most users it isn't so unfortunately I don't see us prioritizing to fix it ourselves.

@karrtikr karrtikr added needs decision feature-request Request for new features or functionality and removed info-needed Issue requires more information from poster triage bug Issue identified by VS Code Team member as probable bug labels Apr 6, 2021
@karrtikr karrtikr removed their assignment Apr 6, 2021
@karrtikr karrtikr closed this as completed Apr 6, 2021
@microsoft microsoft locked and limited conversation to collaborators Apr 6, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
area-terminal feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants