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.

Environment Variable `${env:HOME}` not being recognized in `.env` file when setting PYTHONPATH

See original GitHub issue

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.68.1
  • OS Version: Ubuntu 20.04

Steps to Reproduce:

mkdir python-test && cd python-test
echo "import a" >> main.py 
echo "PYTHONPATH=\$HOME/python-test/external" >> .env 
mkdir external && cd external
touch a.so

open python-test folder with vscode, click main.py, click F5, we get an error

Exception has occurred: ModuleNotFoundError
No module named 'a'

However, if I update .env to PYTHONPATH=/home/jasjuang/python-test/external, I get the expected error

Exception has occurred: ImportError
/home/jasjuang/python-test/external/a.so: file too short

This seems to indicate that vscode is unable to parse the environment variable $HOME in the .env file correctly. I also observe the same problem on macOS, where vscode is unable to parse the environment variable $USER in the .env file correctly.

Is it possible to fix it so that the environment variables are parsed correctly? It would be nice to be able to share the .env file among different machines.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
fabiozcommented, Jul 7, 2022

@karrtikr @karthiknadig this doesn’t really seem related to debugpy (the management of environment variables is not really done at the debugger, rather, it’s done in vscode-python which launches the debugger).

0reactions
karrtikrcommented, Nov 12, 2022

Sorry for all the confusion, debugger doesn’t work due to a bug https://github.com/microsoft/vscode-python/issues/18572. But other features should ideally be working. You can verify this:

  • Try setting python.logging.level to debug in User settings, and install the pre-release version of the extension:

image

  • The Python output should contain something like Dump environment variables where you can see PYTHONPATH should be printed as you expect.

Closing as dup of https://github.com/microsoft/vscode-python/issues/18572

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is ${env:VARNAME} in my VS Code .env file not being ...
I have defined a system environment variable: HOME=d: In my VS CODE .env file, I define a new variable: pythonpath=${env:HOME}\foo.
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 >
Frequently Asked Questions — Ansible Documentation
Setting environment variables can be done with the environment keyword. ... Start of python fails with The module libpython2.7.so was not found.
Read more >
Env vars - Dynaconf - 3.1.11
Environment Variables ¶. Dynaconf prioritizes environment variables over files as the best recommendation to keep your settings.
Read more >
Using .env Files for Environment Variables in Python ...
If an environment variable is not found in the .env file, ... Docker will then set the same environment variables you've been using...
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