How to install Pipenv on Fedora

Pipenv aims to bring the best of all packaging worlds (bundler, composer, npm, cargo, yarn, etc.) to the Python world. It tries to solve a couple of problems and also simplify the whole management process.

Currently the management of Python application dependencies sometimes seems like a bit of a challenge. Developers usually create a virtual environment for each new project and  install dependencies into it using pip. In addition they have to store the set of installed packages into the requirements.txt text file. We’ve seen many tools and wrappers that aim to automate this workflow. However, there was still necessity to combine multiple utilities and the requirements.txt format itself is not ideal for more complicated scenarios.

One tool to rule them all

Pipenv manages complex inter-dependencies properly and it also provides manual documenting of installed packages. For example development, testing and production environments often require a different set of packages. It used to be necessary to maintain multiple requirements.txt  per project. Pipenv introduces the new Pipfile format using TOML syntax. Thanks to this format, you can finally maintain multiple set of requirement for different environments in a single file.

Pipenv has become the officially recommended tool for managing Python application dependencies only a year after the first lines of code were committed into the project.  Now it is finally available as an package in Fedora repositories as well.

Installing Pipenv on Fedora

On clean  installation of Fedora 28 and later you can simply install Pipenv by running this command at the terminal:

$ sudo dnf install pipenv

Your system is now ready to start working on your new Python 3 application with help of Pipenv.

The important point is that while this tool provides nice solution for the applications, it is not designed for dealing with library requirements. When writing a Python library, pinning dependencies is  not desirable. You should rather specify install_requires in setup.py file.

Basic dependencies management

Create a directory for your project first:

$ mkdir new-project && cd new-project

Another step is to create a virtual environment for this project:

$ pipenv --three

The –three option here sets the Python version of the virtual environment to Python 3.

Install dependencies:

$ pipenv install requests
Installing requests…
Adding requests to Pipfile's [packages]…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…

Finally generate a lockfile:

$ pipenv lock
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (b14837)

You can also check a dependency graph:

$ pipenv graph
 - certifi [required: >=2017.4.17, installed: 2018.4.16]
- chardet [required: <3.1.0,>=3.0.2, installed: 3.0.4]
- idna [required: <2.8,>=2.5, installed: 2.7]
- urllib3 [required: >=1.21.1,<1.24, installed: 1.23]

More details on Pipenv and it commands are available in the documentation.

For Developers New in Fedora Using Software

7 Comments

  1. mehdi

    Great article! Gives good insight into Python even for a non-Python (but Python-curious) developer!

  2. Adriano Braga

    I find it unnecessary to install pipenv on your system, since python3.6 already brings pyvenv-3.6
    You can create your isolated environment using python3.6 with the second command:
    python3.6 -m venv namemyvenv

    • Note that pipenv is a tool built on top of venv/virtualenv. It brings more than just the stdlib’s venv tool.

  3. I also suggest to have a look at Fades: https://fades.readthedocs.io/

  4. jg424

    Relevant xkcd: https://xkcd.com/927/

  5. Allad Syrad

    What an awesome tool. So happy to see it packaged in Fedora. Thanks for making this available.

  6. Batisteo

    One should have a look at Poetry, it’s basically as awesome as Cargo for Python, based on PEP 508, and way more pythonic than Pipenv, covering more use cases.
    This should be the recommenced one.
    http://poetry.eustace.io/

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions