Python - pipenv (dependency framework)

> Procedural Languages > Python > Python - (Shipping|Packaging)

1 - About

pip+venv = pipenv

pipenv is a dependency framework for Python.

See https://packaging.python.org/key_projects/#pipenv

Advertising

3 - Managing

3.1 - Install pipenv

3.1.1 - pip

pip install --user pipenv

3.1.2 - PyCharm

3.2 - Steps

3.2.1 - Add dependency

pipenv install package

it will install a Python - virtualenv (Python Environment)

Example

pipenv install requests
Creating a virtualenv for this project…
Pipfile: D:\code\python-gh\Pipfile
Using c:\python37-32\python.exe (3.7.1) to create virtualenv…
Complete
Already using interpreter c:\python37-32\python.exe
Using base prefix 'c:\\python37-32'
New python executable in C:\Users\gerard\.virtualenvs\python-gh-yOsZOOt6\Scripts\python.exe
Installing setuptools, pip, wheel...
done.
Virtualenv location: C:\Users\gerard\.virtualenvs\python-gh-yOsZOOt6
Creating a Pipfile for this project…
Installing requests…
Installation Succeeded
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Success!
Updated Pipfile.lock (444a6d)!
Installing dependencies from Pipfile.lock (444a6d)…
  ================================ 5/5 - 00:00:01

3.2.2 - Pipfile

The created Pipfile (configuration). The Pipfile is used to track which dependencies your project needs.

Pipfile
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
 
[[source]]
url = "http://hostname/repository/pypi-all/simple/"
name = "pypi-aap"
verify_ssl = false
 
[dev-packages]
 
[packages]
requests = "*"
 
[requires]
python_version = "3.7"

where:

Advertising

3.2.3 - Activate / use the virtual env

To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Example:

  • pipenv shell
pipenv shell
Launching subshell in virtual environment…
Microsoft Windows [Version 10.0.16299.726]
(c) 2017 Microsoft Corporation. All rights reserved.

(python-gh-yOsZOOt6) d:\code\python-gh>
  • pipenv run
pipenv run python main.py

4 - Documentation / Reference