Repository navigation
Python scripts are executed with the wrong path separator in integrated Powershell on Windows #17215
Description
Discussed in #15870
Originally posted by tsbertalan September 5, 2020
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.languageServersetting: 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:
- Use "Python: Select Interpreter" to launch a file dialog and locate python.exe in
C:\Users\USERNAME\Anaconda3\envs\ENVNAME. - Use
python.execInTerminal(the little play button) to launch a script, withterminal.integrated.shell.windowsunset (that is, left to its default ofC:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe). - Witness the forward-slash generated command in the integrated terminal.
Details
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.
Activity
brettcannon commentedon Sep 1, 2021
Thanks for the feature request! We are going to give the community 60 days from when this issue was created to provide 5 👍 upvotes on the opening comment to gauge general interest in this idea. If there's enough upvotes then we will consider this feature request in our future planning. If there's unfortunately not enough upvotes then we will close this issue.
brettcannon commentedon Nov 1, 2021
Thank you for submitting your feature request and everyone who considered it! Unfortunately this issue did not receive enough votes over the allotted time, and so we are closing the issue.