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.

Tasks with active venv get `source /path/to/activate` as stdin

See original GitHub issue

Environment data

  • VS Code version:

    • Version: 1.41.1
    • Commit: 26076a4de974ead31f97692a0d32f90d735645c0
    • Date: 2019-12-18T15:04:31.999Z
    • Electron: 6.1.5
    • Chrome: 76.0.3809.146
    • Node.js: 12.4.0
    • V8: 7.6.303.31-electron.0
    • OS: Linux x64 5.4.7-arch1-1
  • Python Extension version: 2019.11.50794

  • Python version: 3.8.1

  • Type of virtual environment: venv

Expected behaviour

When configuring a task via the .vscode/tasks.json file and running it, the terminal used should change to the venv set and stdin should be empty for the commands in the task configuration to use (eg. when using read in a bash script).

Actual behaviour

When running a task, (via command palette: ‘Run Task’) stdin is filled with the command:
source /path/to/activate. If the command set in the task, reads from stdin, it gets this string. This only happens if the terminal window is fresh (previous terminals were killed). For repeated runs of the task in the same terminal (without setting presentation{"panel":"new"}), this behaviour is not observed.

The command to load the venv (via source […]/activate) should not be executed after the command from the task, but instead at the very beginning. It also should not fill up stdin.

When not having set a venv interpreter, the issue is not present.

Steps to reproduce:

zipped archive of the files and venv: files.zip

  1. create a new venv
  2. open the folder in vscode
  3. set the interpreter to the new venv
  4. add these three files:

./a.py

print(input("your input: "))

./b.sh

read a
echo $a

echo $VIRTUAL_ENV

.vscode/tasks.json

{
   "version": "2.0.0",
    "tasks": [
        {
            "label": "python",
            "type": "shell",
            "command": "${config:python.pythonPath} a.py",
            "presentation": {
                "focus": true,
                "panel": "new"
            },
            "problemMatcher": []
        },
        {
            "label": "bash",
            "type": "shell",
            "command": "./b.sh",
            "presentation": {
                "focus": true,
                "panel": "new"
            },
            "problemMatcher": []
        }
    ]
}

Now use the command palette and run either task (‘python’ or ‘bash’). When running the task in a fresh terminal, the output will be: python:

> Executing task: cleanvenv/bin/python3 a.py <

your input: source /tmp/files/cleanvenv/bin/activate
source /tmp/files/cleanvenv/bin/activate

Press any key to close the terminal.

bash:

> Executing task: ./b.sh <

source /tmp/files/cleanvenv/bin/activate
source /tmp/files/cleanvenv/bin/activate

Press any key to close the terminal.

For the bash version, there is also no environment variable $VIRTUAL_ENV set.

Remarks

I hope the explanations were clear enough. I am very new to issue reporting. Please let me know, if I missed anything.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brettcannoncommented, Jan 7, 2020

Thanks for the bug report! We just wanted to quickly acknowledge we received it and we will triage this as soon as we can.

0reactions
karthiknadigcommented, May 13, 2020

This issue should be resolved when we support #11039. This way we will not be sending the activate command to terminal at all. Closing this in favor of the above issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Auto activate virtual environment in Visual Studio Code
I want VS Code to turn venv on run, but I can't find how to do that. I already tried to add to...
Read more >
venv — Creation of virtual environments — Python 3.11.1 ...
Source code: Lib/venv/ The venv module supports creating lightweight “virtual ... Creation of virtual environments is done by executing the command venv :....
Read more >
Python Virtual Environments: A Primer
In this tutorial, you'll learn how to work with Python's venv module to create and manage separate virtual environments for your Python ...
Read more >
Pipenv & Virtual Environments
virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need. It can be...
Read more >
Virtualenv and venv: Python virtual environments explained
Once you've activated the new virtual environment, you can use the pip package manager to add and change packages for it. You'll find...
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