A personal workflow for django, poetry, and pyenv

This is a personal workflow for making django, poetry, and pyenv work together. Requires poetry, pyenv, git-flow and wget.

By Ace Z. Alba

Published on May 13, 2023, 3:08 pm

Category: workflow

Tag: python, poetry, pyenv

mkdir MyProject
cd MyProject
poetry init

Set a local python version

pyenv local 3.10.2

Check this poetry config by running the command below. This config is required for poetry to recognize the version set by pyenv local.

poetry config virtualenvs.prefer-active-python true

Try spawning a virtual environment using poetry shell. Check with python3 --version if your poetry is using the correct version. If not, close the virtual environment with exit, delete the virtualenv files, and run the command below to force poetry to use a specific python version.

pyenv shell 3.10.2

Then spawn your virtual environment again.

poetry shell

Install dependencies

poetry install

Start git-flow init (just to create the initial git flow branching settings)

git-flow init

Set the .gitignore

wget https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore --output-document .gitignore

Commit the gitignore

git add .gitignore
git commit -m "set the project gitignore"

Create an django administrator app named admin

django-admin startproject proj_myproject .

Create a django app in directory

python manage.py startapp app_myappname

Manually register myproject in admin/settings.py with the line myproject.apps.MyprojectConfig, in INSTALLED_APPS array

Migrate changes.

python manage.py migrate
python manage.py runserver

Commit the rest

git add -A
git commit -m "Initial commit for project files."