Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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://imgur.com/a/h3Ji8ZO

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
like image 670
user8491363 Avatar asked Aug 15 '19 06:08

user8491363


People also ask

How do you activate Pipenv in VSCode?

pipenv and VSCode The only way is to pythonPath explicitly declare it in . vscode/settings. json . To get the path of the virtual environment created by pipenv , you first need to go into the root directory of your project (on the same level as the Pipfile) and run the command pipenv --where or pipenv --venv .

Where is Pipenv located?

Pipenv installs packages in ~/. local/share/virtualenvs/<your-virtualenv> by default. I prefer to place the folder containing the virtual environment in the project itself. This way you always delete the virtual environment along with your project when you're done.

How do I enable Pipenv?

To activate the environment, just navigate to your project directory and use pipenv shell to launch a new shell session or use pipenv run <command> to run a command directly.

Where is the Pipenv executable?

Discover the proper executable path as described in the pipenv installation procedure and enter the target string in the Pipenv executable field, for example: C:\Users\jetbrains\AppData\Roaming\Python\Python37\Scripts\pipenv.exe (Windows) or /Users/jetbrains/. local/bin/pipenv (macOS).


1 Answers

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.

like image 139
user8491363 Avatar answered Sep 20 '22 18:09

user8491363