简体   繁体   中英

Is python interpreter in vscode using pipenv or venv

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM