I have been using pipenv to help me manage my python virtual environments.
I also use Heroku for some of my sites…and Heroku relies on the requirements.txt file rather than Pipfile/Pipfile.lock that pipenv uses.
Here is an easy way to generate a requirements.txt file from a Pipfile.lock
jq -r '.default
| .key + .value.version' \
Pipfile.lock > requirements.txt
NOTE: You will need the program ‘jq‘ (like sed for JSON data) installed, which can be done via:
sudo apt install jq
I believe that I learned about this method inside the issues tracker for pipenv on GitHub.
Pip environments with python and django have evolved over the years, but once constant has remained: virtual environments to run the code and packages in. The latest consensus is to use pipenv to keep things separated. Let’s see how.
First, I’ll assume that you already have python 3.7 installed. If you need help, check out this other post I wrote: https://markcerv.com/2019/03/adding-python-3-7-to-ubuntu-18-x/
sudo apt install python-pip
sudo pip install pipenv
pipenv --python 3.7 install django
In order to use pipenv, you will need to cd to the directory where you want to put your code, and then:
pipenv --python 3.7 install django django-cors-headers \
# a bunch of things will happen, including that a virtualenv
# will get get created like:
# to actually fire up the environment
Next, you’ll need to setup a minimum of files to get django going. :
django-admin startproject test2
python manage.py migrate #will setup the needed database stuff
python manage.py createsuperuser # lets you make a u/p for login
./manage.py runserver 0.0.0.0:8000
You can now jump over to a browser, and visit http://127.0.0.1:8000/admin/ and sign in to your app. It’s pretty boring right now, but you can fix that.
If you quickly want to get the latest version of Python installed on Ubuntu and get future updates automatically, then you can install it from the below third-party PPA repository…
To do that, run the commands below to add the PPA.
First install Ubuntu software properties package if it’s not already installed on your system..
sudo apt update
sudo apt install software-properties-common
After that run the commands to add the PPA..
sudo add-apt-repository ppa:deadsnakes/ppa
Finally, run the commands below to install Python 3.7
sudo apt update
sudo apt install python3.7