February 10, 2019

November 25, 2019

pipenv and pyenv

What's pyenv?

It's like nvm but for Python ;-)

Install pyenv.

brew install pyenv

How to use it?

Install a specific Python version:

pyenv install 3.7.0

Activate a specific version:

pyenv shell 3.7.0

List all installed versions.

pyenv versions

You can find all the commands here.

What's pipenv?

Installation.

brew install pipenv

Enable shell completion.

How to use it?

Go to your project and create virtualenv.

pipenv

You can also specify Python version.

pipenv --python 3.7.1

You can create .python-version file inside your project with a version number, like 3.7.1. Specified Python version will be activated automatically when you enter to the project directory. It will also automatically install the specified version if pyenv is installed.

If you want to install package, use pipenv instead of pip.

pipenv install django

It will add a package to Pipfile file and Pipfile.lock. If you want to install all packages from Pipfile, use pipenv install command.

If you want to install a package required only for development, add --dev flag.

pipenv install pytest --dev

pipenv can also load environment variables from .env files.

  1. Create .env file with your variables.
  2. Run pipenv shell.

You can scan your dependency graph for known security vulnerabilities:

pipenv check

More information here.

© 2020 Przemysław Kołodziejczyk