Explain once and for all how to set python.pythonPath using environment variables or remove this from docs
See original GitHub issueEnvironment data
- VS Code version: 1.44.0
- Extension version (available under the Extensions sidebar): 2020.2.64397
- OS and version: Linux x64 5.5.8-arch1-1
- Python version: Virtual env python 2.7
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): Pipenv
- Jedi or Language Server?: disabled
- Value of the
python.languageServer
setting: Microsoft
Expected behaviour
From reading the docs, it seems to suggest that one can set python.pythonPath
using environment variable.
I have a .env
file with the content:
PYTHON_INSTALL_LOC="/home/chigozirim/dev/virtualenvs/XXX/bin/python"
And I have set the value of python.pythonPath
using:
"python.pythonPath": "${env:PYTHON_INSTALL_LOC}"
I expect the plugin to pick up the actual path from the environment variable and use that python
Actual behaviour
The plugin fails to see the python I specified and instead picks up the system default python, which means the variable is resolving to an empty string
Steps to reproduce:
Use my setup above, with the .env
file.
Directory structure
➜ tree -aL 1
.
├── data
├── .env
├── fig
├── .git
├── .gitignore
├── mnist
├── Pipfile
├── Pipfile.lock
├── .pylintrc
├── README.md
├── run.ps1
├── src
└── .vscode
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
[Info - 6:41:44 p.m.] Analysis cache path: /home/chigozirim/.cache/Microsoft/Python Language Server
[Info - 6:41:44 p.m.] Microsoft Python Language Server version 0.5.31.0
[Info - 6:41:44 p.m.] Workspace root: /home/chigozirim/projects/neural-networks-and-deep-learning-py
[Info - 6:41:44 p.m.] GetCurrentSearchPaths /usr/bin/python
[Info - 6:41:44 p.m.] Interpreter search paths:
[Info - 6:41:44 p.m.] /usr/lib/python3.8
[Info - 6:41:44 p.m.] /usr/lib/python3.8/lib-dynload
[Info - 6:41:44 p.m.] /home/chigozirim/.local/lib/python3.8/site-packages
[Info - 6:41:44 p.m.] /usr/lib/python3.8/site-packages
[Info - 6:41:44 p.m.] User search paths:
[Info - 6:41:44 p.m.] /home/chigozirim/projects/neural-networks-and-deep-learning-py/src
[Info - 6:41:47 p.m.] Initializing for /usr/bin/python
[Info - 6:41:47 p.m.] Analysis caching mode: None.
In case I’m not making myself clear, I am referring to where it states in the docs:
By default, the Python extension looks for and loads a file named
.env
in the current workspace folder, then applies those definitions. The file is identified by the default entry"python.envFile": "${workspaceFolder}/.env"
in your user settings (see General settings). You can change thepython.envFile
setting at any time to use a different definitions file.
I’m certain this means that the extension is supposed to read the .env
file and use the values found there. If that’s the case, why does it fail to use the environment variables I set, to fill in python.pythonPath
?
I just need to know if this feature is supported or not and what the docs means when it specifies the use of environment variables for setting the python.pythonPath
. If this is actually not supported, then I strongly suggest it should be, otherwise it should not be in the docs so that devs are not being misled and end up wasting time on something that wasn’t supposed to work.
See also: https://github.com/microsoft/vscode-python/issues/944#issuecomment-370512814
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top GitHub Comments
@smac89, thanks for getting in touch with us about this. We’ll get back to you as soon as possible.
Thanks for bringing this up! We’ll update the docs accordingly. FWIW, we’re also deprecating the python.pythonPath setting (https://github.com/microsoft/vscode-python/issues/2125).
Closing in favour of https://github.com/microsoft/vscode-docs/issues/3550 and #11015.