question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Explain once and for all how to set python.pythonPath using environment variables or remove this from docs

See original GitHub issue

Environment 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 (ViewOutput, 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 the python.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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ericsnowcurrentlycommented, Mar 13, 2020

@smac89, thanks for getting in touch with us about this. We’ll get back to you as soon as possible.

0reactions
luabudcommented, Apr 10, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using PYTHONPATH — Functional MRI methods
PYTHONPATH is an environment variable. See the Python 3 docs for PYTHONPATH. The PYTHONPATH variable has a value that is a string with...
Read more >
Understanding the Python Path Environment Variable in ...
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 >
How do I set PYTHONPATH and other environment ...
Setting the PYTHONPATH environment variable is an easy way to make Python modules available for import from any directory. This environment ...
Read more >
Using Python environments in VS Code
The PYTHONPATH environment variable specifies additional locations where the Python interpreter should look for modules. In VS Code, PYTHONPATH can be set ......
Read more >
1. Command line and environment
In isolated mode sys.path contains neither the script's directory nor the user's site-packages directory. All PYTHON* environment variables are ignored, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found