Search code examples
bashterminalvisual-studio-codepipenv

Pipenv on VSCode: Why is (pipenv) not displayed on the terminal?


I'm setting up pipenv virtual environment on VSCode Bash terminal but it's not showing (pipenv), which makes it very confusing.

When I was using Pycharm and let it configure pipenv environment, it would automatically display (pipenv) after the project path so it was very easy to tell whether I was on pipenv or not.

After I moved to VSCode, I made a project directory and started a pipenv environment inside it by $ pipenv shell which initialized pipenv stuffs fine but (pipenv) is not displayed on the shell and instead shown on the right corner of the terminal like this: https://i.sstatic.net/SkfuC.jpg

How terminal is shown seems to be managed by scripts/activate file but it seems the problem is somewhat related to both pipenv and VSCode so I'm not sure how to address this problem properly.

Here's some of the codes related to my settings.

Jill@Jill-PC MINGW64 /e/VSCodeProjects/likelion (master)
$ pip -V
pip 19.2.1 from c:\users\jill\.virtualenvs\likelion-wdstza1r\lib\site-packages\pip (python 3.6)

Jill@Jill-PC MINGW64 /e/VSCodeProjects/likelion (master)
$ python --version 
Python 3.6.4 :: Anaconda, Inc.

Jill@Jill-PC MINGW64 /e/VSCodeProjects/likelion (master)
$ pipenv --version
pipenv, version 2018.11.26

Solution

  • To answer my own question, it was because I was rather unfamiliar with how VSCode works.

    Unlike IDEs like Pycharm, VSCode doesn't 'remember' the previously used Python interpreter. This means that the Bash you see when you open up VSCode or when you first created a virtual environment with pipenv is not the virtual environment's shell.

    You'll have to first select your Python interpreter from the command palette and close the current bash shell by clicking trash can button and open up the shell again. Then you'll see (venv_name) on the Bash's prompt which indicates that you're on the virtual environment you created.