2

I selected my python interpreter to be the one pipenv created with pipenv shell in vscode. Then if I open the terminal/cmd manually or run a script using the play button up on the right, the new terminal/cmd opened will run the activate script which runs the terminal in the virtual environment. My question here is, is it using my pipenv environment or venv environment? Because if i run the pipenv shell or pipenv install, it will say that "Pipenv found itself running within a virtual environment, so it will automatically use that environment...". And also if i type exit, instead of terminating that environment, it closes the terminal.

2 Answers 2

2

You are using the python interpreter which is shown at the bottom-left of the VSCode.

Even you activate a virtual environment created by pipenv in the terminal, it will have no affection on the new terminal and execute the python code.

And if the pipenv found it was in a virtual environment it will not create a new virtual environment with the command pipenv install. And if you execute pipenv shell, it is still in the virtual environment which you activated before. And you can check which python you are using to verify it.

Sign up to request clarification or add additional context in comments.

4 Comments

So just to confirm that... Although the terminal is not activated by pipenv(im guessing vscode is using venv activation) , if i run any python script, im technically using the pipenv environment?
@danialsaufi It depends on which python interpreter you have selected. You can get it from the bottom-left of the VSCode.
I only have one interpreter which was created by pipenv and i choose it already. However, when the terminal is activated, instead of (name of folder - [id]) it just shows (name of folder). If im not mistaken, (name of folder - [id]) is pipenv while (name of folder) is venv.
Worked out for me but it was bottom-right instead of bottom-left.
1

This is the way I usually interact with pipenv:

  • to check if you're on pipenv and not venv you pip graph. If the terminal prints Courtesy Notice: Pipenv found itself running within a virtual environment(...) then it means you're in a regular venv
  • You can then deactivate and pipenv shell if you want to do it clean or just straight pipenv shell (I don't know if there is any difference) and the terminal will load environment variables and activate the pipenv environment for the remainder of it's duration.
  • After this you can reload the interpreters and pick the Python(...):pipenv option.
  • If you exit here, you will return to your regular venv, after which you can exit to close the terminal or deactivate to return to your global environment.

venv uses the same folder as pipenv. The installed packages are also the same, you can check by running pip graph and pip list so it's just a matter of running pip shell manually.

I'd love to know if there is some way to activate the environment in VS Code automatically from pip shell instead.

1 Comment

That's a good alternative. But yep it would be super great if it was more like automatic because at one point you would sometimes forget to check that and wound up using the venv environment and not the pipenv. From what i understand from some research, it is an ongoing problem in virtual environment which i think could only be solved by the vscode dev themselves.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.