Install pip3, pipenv, pyenv and Django on Linux Mint 19.2

Setting Up To Develop with Python 3 on Linux Mint 19.2

When trying to set up a machine for local Python development, we need several tools to make our lives easier. We’re going to want to use virtual environments and package management tools, but there are lots of options. The Python 3 Tutorial suggests using venv for managing virtual environments and pip for managing packages, and that works great!

There is a newer tool called pipenv that streamlines both virtual environment and dependency management. The tagline for the project is Python Development Workflow for Humans.

From the project repo:

The problems that Pipenv seeks to solve are multi-faceted:

– You no longer need to use pip and virtualenv separately. They work together.

– Managing a requirements.txt file can be problematic, so Pipenv uses the upcoming Pipfile and Pipfile.lock instead, which is superior for basic use cases.

– Hashes are used everywhere, always. Security. Automatically expose security vulnerabilities.

– Give you insight into your dependency graph (e.g. $ pipenv graph).

– Streamline development workflow by loading .env files.

I had a few issues getting everything set up on my Linux laptop. You have to be careful to not break the system Python installation (like I did). So I’m documenting how I was able to get things set up using Linux Mint 19.2.

To get started, we need to install pip3:

Then install pipenv, calling pip as a module from Python 3:

I wanted to use the feature in pipenv that allows it to automatically install versions of Python for its virtual environments. For that, we need to install pyenv. I used the Basic Github Method to install it on Linux Mint. Be sure to follow all the setup steps to get it working. I initially forgot to install the build dependencies. The command for Linux Mint (Ubuntu) is:

Now we should be set up to use pipenv to start a new Python 3 project:

Assuming you don’t have a Python 3.7 installation (Linux Mint default Python3 is currently version 3.6.8) this should ask if you want to install version 3.7.x using pyenv. After you confirm, pyenv will download and install the version of Python you specified, then create a virtual environment and a Pipfile for the project. Now we can install dependencies.

I’m going to build an API using Django and Django Rest Framework, so I’ll install those as an example. Calling pipenv as a module with Python 3:

Assuming everything goes well, pipenv will download django and django-rest-framework, update the Pipfile, create and update the Pipfile.lock, and install the new dependencies from the lock file.

If you want to enter a shell for the virtual environment:

Now to get the Django project started:

To start the server and verify the project is running:

Then open in a browser, and you should see the default Django page.

From here you can start developing your project, or check out the pyenv Github repo or official documentation for more info.

If you have any questions or comments about this post let me know!

Chris Bryant / September 21, 2019 / linux, programming, python, uncategorized
Tags: , , ,