Python/PipEnv: Difference between revisions

From Dev Wiki
Jump to navigation Jump to search
(Create PipEnv page)
 
(Add command)
 
Line 34: Line 34:
  python3 -m pip install --user pipenv
  python3 -m pip install --user pipenv


=== Project Setup Commands ===
=== Package Management Commands ===
{{ note | For the below commands, you can also add the {{ ic |--dev}} flag, which tells PipEnv to install optional "dev-packages" to the local Python environment. Aka, those dependencies that were defined in the "development section" of the PipFile.}}
{{ note | For the below commands, you can also add the {{ ic |--dev}} flag, which tells PipEnv to install optional "dev-packages" to the local Python environment. Aka, those dependencies that were defined in the "development section" of the PipFile.}}


Line 45: Line 45:
Update a specific dependency (warning - may also update unrelated dependencies):
Update a specific dependency (warning - may also update unrelated dependencies):
  pipenv update <dependency>
  pipenv update <dependency>
Uninstall a specific dependency with:
pipenv uninstall <dependency>

Latest revision as of 01:43, 12 November 2022

PipEnv is an attempt to make Python Pip behave more like Composer (from Php/Laravel).

In other words, this is meant to streamline project package/environment management. You tell PipEnv what packages you care about, and it effectively installs + manages versions (and sub-dependency versions) for you.
This data is stored in files called PipFile and PipFile.lock, at your project root.


Official docs can be found at https://docs.pipenv.org/

This page shows quick, basic options for ease of use.


Linux Setup

Before using PipEnv, it's recommended to add some additional settings to the local system environment. To do this, edit the user's local .bashrc file (or equivalent) and add the following:


Update terminal path to find PipEnv:

export PATH="$PATH:/home/<username>/.local/bin"

Update PipEnv settings to always use venv folders in project:

export PIPENV_VENV_IN_PROJECT=true


Reminder to restart terminal after saving changes.


Important Commands

Install Commands

Install PipEnv for Mac:

brew install pipenv

Install PipEnv for Linux:

python3 -m pip install --user pipenv

Package Management Commands

Note: For the below commands, you can also add the --dev flag, which tells PipEnv to install optional "dev-packages" to the local Python environment. Aka, those dependencies that were defined in the "development section" of the PipFile.

Install current project dependencies to the local Python environment, as listed in PipEnv files:

pipenv sync

Update project dependencies listed in PipEnv files, then install them to the local python environment:

pipenv install

Update a specific dependency (warning - may also update unrelated dependencies):

pipenv update <dependency>

Uninstall a specific dependency with:

pipenv uninstall <dependency>