简体   繁体   中英

How can I know which python a pipenv venv is using?

I am managing dependencies with pipenv . I have several python installs on my system.

How can I know which python install has been used to create the venv ?

I tried the following:

pipenv --venv

-> Just returns venv location, not python's original location

pipenv --py

-> Just returns location of python exe in venv, not original location

pipenv run python -V

-> Just returns version of python

Inside the virtualenv folder, there is a pyvenv.cfg file which contains information about the Python interpreter used for the virtual environment:

home = /usr
implementation = CPython
version_info = 3.8.5.final.0
virtualenv = 20.1.0
include-system-site-packages = false
base-prefix = /usr
base-exec-prefix = /usr
base-executable = /usr/bin/python3

As explained by Python documentation: venv

Running this command creates the target directory (creating any parent directories that don't exist already) and places a pyvenv.cfg file in it with a home key pointing to the Python installation from which the command was run (a common name for the target directory is .venv ). It also creates a bin (or Scripts on Windows) subdirectory containing a copy/symlink of the Python binary/binaries (as appropriate for the platform or arguments used at environment creation time). It also creates an (initially empty) lib/pythonX.Y/site-packages subdirectory (on Windows, this is Lib\\site-packages ). If an existing directory is specified, it will be re-used.

sys.executable holds the path to the python executable that is currently running.

So you can find the path to your version using the following line:

pipenv run python -c "import sys; print(sys.executable)"

On windows i can use which on powershell to get the path of pipenv.

> which pipenv
... Source
... D:/programs/python/Scripts/pipenv.exe

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