Fix support for folders in python.pythonPath setting
See original GitHub issueEnvironment data
- VS Code version: 1.54.3
- Extension version (available under the Extensions sidebar): v2021.3.680753044
- OS and version: Windows 10.0.19041
- Python version (& distribution if applicable, e.g. Anaconda): 3.8.6
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv (via poetry)
- Value of the
python.languageServer
setting: Pylance
Expected behaviour
For "python.pythonPath": "${workspaceFolder}/.venv"
workspace setting, extension is expected to find the virtualenv in the given directory.
Actual behaviour
The extension is unable to find the virtual env with the latest update (rolling back to the previous version works fine).
Steps to reproduce:
- Create a virtualenv in the workspace possibly using poetry, and point to the workspace with ${workspaceFolder}/{workspace_name}
IMPORTANT NOTE: ".venv\\Scripts\\python.exe"
works fine, but "${workspaceFolder}\\.venv"
, "${workspaceFolder}/.venv"
does not. All of them works in the previous version.
Possibly related to #15781 but I do not have the error described in that issue in the output below.
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
User belongs to experiment group 'pythonaa'
User belongs to experiment group 'pythonJoinMailingListVar2'
User belongs to experiment group 'pythonJediLSP'
User belongs to experiment group 'pythonSendEntireLineToREPL'
User belongs to experiment group 'pythonNotDisplayLinterPrompt'
User belongs to experiment group 'pythonDiscoveryModuleWithoutWatcher'
User belongs to experiment group 'pythonFindInterpreter'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'CollectLSRequestTiming - control'
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Starting Pylance language server.
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> c:\Users\erena\OneDrive\Desktop\SNLab\soccerbars/.venv c:\Users\erena\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
Error 2021-03-25 12:24:27: Diagnostic Code: InvalidPythonInterpreterDiagnostic, Message: No Python interpreter is selected. You need to select a Python interpreter to enable features such as IntelliSense, linting, and debugging.
Diagnostic Code: InvalidPythonInterpreterDiagnostic, Message: No Python interpreter is selected. You need to select a Python interpreter to enable features such as IntelliSense, linting, and debugging.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:17
Top Results From Across the Web
Fix support for folders in python.pythonPath setting #15782
For "python.pythonPath": "${workspaceFolder}/.venv" workspace setting, extension is expected to find the virtualenv in the given directory. Actual behaviour.
Read more >How to correctly set PYTHONPATH for Visual Studio Code
I have a situation that I believe is relatively common. I want a script to import a module from another directory. My python...
Read more >Settings Reference for Python - Visual Studio Code
Python settings reference. The Python Extension for Visual Studio Code is highly configurable. This page describes the key settings you can work with....
Read more >Understanding the Python Path Environment Variable in Python
Python path is an environment variable used to maintain directories of custom Python libraries. Learn how to set a python path variable on ......
Read more >Usage of PYTHONPATH - Discussions on Python.org
The PYTHONPATH environment variable is not for setting the standard library and site packages directories. Python adds those on its own. By ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@karrtikr thanks a lot! Just to note my use case: I use poetry in all my projects with with the poetry.toml:
looking like this, and
"python.pythonPath": "${workspaceFolder}/.venv"
. So, when someone clones the repository and just runspoetry install
, vscode uses the created environment and everything runs perfectly, with zero OS dependence. If vscode decides that we have to explicitly write the binary, though, then the OS independence would be lost since what vscode is automatically doing right now would have to be done manually by the user (and less meta-shenanigans the better especially for people who are not familiar with vscode and/or python). If you can take this use case into consideration that would be really amazing (this might be the single most important setting that has to be shared between the developers/users of a python package for consistency).FYI Insiders build should now have the fix.