DarkMatter in Cyberspace
  • Home
  • Categories
  • Tags
  • Archives

Python Project and Package Management with pipenv


pipenv is a modern packaging tool like npm (for node.js), leiningen (for clojure) or gradle (for java, groovy). Install with pip install pipenv or pip install --user pipenv.

Basic workflow

mkdir myproj; cd myproj
pipenv install flask pudb --three
# create Pipfile which is the equivalent of package.json (for node.js),
# build.gradle (for gradle).  here `--two/three` means using Python 2 or 3

# Or with specific Python version:
pipenv install baidupcsapi ipython requests requests_toolbelt --python 3.5

# Or build with multiple steps:
pipenv --python 3.6   # create a new environment using Python 3.6
pipenv install flask
pipenv install pudb

pipenv shell          # activate the virtual environment
pipenv uninstall flask
exit                  # leave the virtual environment, or Ctrl-d
pipenv --rm        # remove the virtual environment created by `pipenv install`
pipenv install     # install packages in Pipfile (and the lock file)

Add Pipfile.lock into git version control. See Issue 598 for explanations.

Working with an existing Python project

For a project already contains Pipfile or requirements.txt: pipenv install (this command create a Pipfile automatically based on requirements.txt).

Install develop package

The packages required by application is called default pakcage in pipenv jargon. That used only for development purpose is dev packages. For example, when developing a i3ipc application for i3wm:

$ cat Pipfile
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]

"i3ipc" = "*"

[dev-packages]

pyinstaller = "*"
ipython = "*"
flake8 = "*"
yapf = "*"

[requires]

python_version = "3.7"

Here all packages in [dev-packages] is not required by the final application, but for development. For example flake8 and yapf are linters, ipython is REPL, and pyinstaller is the package tool.

Install both develop and default packages with pipenv install -d or pipenv install --dev.

Working with conda

See pipenv and conda for details.

Other Python Environment Manager

pyenv + pip-virtualenv + pip-tools.

This solution is more lightweight than pipenv. See is pipenv still the "official" reccomended tool for packaging? for more discussions.



Published

Nov 6, 2017

Last Updated

May 20, 2019

Category

Tech

Tags

  • package 28
  • pipenv 1
  • python 136

Contact

  • Powered by Pelican. Theme: Elegant by Talha Mansoor