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.

Unintended removal of valid "sys.path" entries by isolation script

See original GitHub issue

Environment data

  • VS Code version: 1.45.1
  • Extension version (available under the Extensions sidebar): 2020.5.78807
  • OS and version: ArchLinux (May)
  • Python version: 3.8.2 (ArchLinux)
  • Type of virtual environment used: pipenv
  • Jedi or Language Server: Language Server
  • Value of the python.languageServer setting: Microsoft

Expected behaviour

After starting a debug session of a pytest test function, sys.path should contain all entires which are avialable if you would run pytest ... from a terminal.

Actual behaviour

The isolation script does not only remove entries from sys.path which are related to VSCode, it will also remove one additional entry from sys.path which may break your debug session.

Steps to Reproduce

  1. Clone Example Repository

  2. Run pipenv sync --dev and pipenv run pip install -e src from the repository root.

  3. Make sure to execute commands in a pipenv shell.

  4. Run pytest tests/ which should work.

  5. Open repository in VSCode and use pipenv environment as python interpreter.

  6. Debug the example test function, you will recieve ModuleNotFoundError: No module named 'exampleproject'.

Workaround 1

  1. Remove del sys.path[0] from ~/.vscode-oss/extensions/ms-python.python-XXXX.X.XXXXX/pythonFiles/pyvsc-run-isolated.py.

  2. Debug the example test function, it should work now.

Workaround 2

  1. Remove .env from repository root.

  2. Debug the example test function, it should work now.

Explanation of Problem

The tests of the example project uses an editable installation of the exampleproject package. If you start a debug session, sys.path is modified to run the test in an isolated environment. Unfortunately, not only the vscode related entries are removed, but an additional entry is also modified. This entry is the path of the editable installation if you use the provided .env file and will result in failed tests because exampleprojec is missing in the python path. If you do not use the .env file, the debug session might work but (in my case) /usr/lib/python38.zip is removed/replaced.

This may lead to unexpected behavior of debug sessions.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ericsnowcurrentlycommented, Jul 20, 2020

We’ve landed a fix. It will go out in the August release.

0reactions
ericsnowcurrentlycommented, Jul 20, 2020

Probably the simplest solution is to replace sys.path[0] with a known non-existent dirname, rather than removing the entry. I’ll put up a PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting the PYTHONPATH with terminal.integrated.env.* does ...
Current workaround for debugging: see Unintended removal of valid "sys.path" entries by isolation script #11875.
Read more >
Removing path from Python search module path
$PYTHONPATH is an environment variable which is getting appended to sys.path on interpreter startup. So, again, it is related to module search ...
Read more >
Interpreter independent isolated/virtual environments - #33 by ...
The problem with PYTHONPATH is it does not allow removing an existing sys.path entry. You can see from the example above that __PYVENV_LAUNCHER__...
Read more >
Diff - 9ca2fc13f96e6e4867238f129cb6987373c6c705^! - chromium ...
os.environ.pop('PYTHONPATH', None) - bin_dir = 'Scripts' if ... indent=1, with_implicit=True): - for dep, entry in deps.iteritems(): - if not with_implicit ...
Read more >
Scripting the Unreal Editor Using Python
Describes how to use Python in the Unreal Editor to script content ... content is added to sys.path , regardless of the isolation...
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