I currently have a small example blog online.
It works as expected, except for the image upload.
https://django.watchduck.net/posts/create

Trying to upload an image creates an error, because Pillow is not installed:
ModuleNotFoundError at /posts/create
No module named 'PIL'

So I could probably install it like this:
[watchduck@opal9 my_django_app]$ pip install Pillow.
But I would like to know what I am doing.
Would that be a global installation, or would it be specific to this app?

I would prefer to make such installations specific to each Django app.
For Pillow it probably does not matter.
But I could have different Django apps, that require different versions of NumPy.

    Watchduck To install Pillow (or any other dependency) for the specific application you're working on, you must activate the app's Python environment first, like this:
    source /home/your_user/apps/your_app_name/env/bin/activate
    (replace "your_user" and "your_app_name" with your actual shell user and the name of your app)

    More info on installing packages is available in our user guide: Installing Python dependencies for your project

    Thanks, that worked.

    [watchduck@opal9 my_django_app]$ source env/bin/activate
    
    (env) [watchduck@opal9 my_django_app]$ pip install Pillow
    Successfully installed Pillow-10.2.0
    
    (env) [watchduck@opal9 my_django_app]$ pip list
    Package           Version
    ----------------- -------
    asgiref           3.8.1
    Django            4.1.8
    pillow            10.2.0
    pip               23.0.1
    setuptools        65.5.0
    sqlparse          0.4.4
    typing_extensions 4.10.0
    uWSGI             2.0.24

    I am not sure, to what extent I have to keep the global installations in mind.
    E.g. there is numpy (1.7.1). Could I use that in each Django app, when there is no local NumPy?

    (env) [watchduck@opal9 my_django_app]$ deactivate
    [watchduck@opal9 my_django_app]$ pip list
    acme (1.11.0)
    backports.ssl-match-hostname (3.5.0.1)
    ...
    numpy (1.7.1)
    parsedatetime (2.4)
    perf (0.1)
    pip (8.1.2)
    ...
    yum-metadata-parser (1.1.4)
    zope.component (4.1.0)
    zope.event (4.0.3)
    zope.interface (4.0.5)

    For the sake of completeness, I want to mention the Python versions:

    [watchduck@opal9 my_django_app]$ python --version
    Python 2.7.5
    [watchduck@opal9 my_django_app]$ python3 --version
    Python 3.6.8
    
    [watchduck@opal9 my_django_app]$ source env/bin/activate
    
    (env) [watchduck@opal9 my_django_app]$ python --version
    Python 3.10.13

    Let's say I want to use 3.12 for one Django app, but keep the others as they are.
    Can that easily be done?
    (It probably sounds like nothing could go wrong, but on my Ubuntu this was a mess.)

    • sean replied to this.

      Watchduck

      Watchduck I am not sure, to what extent I have to keep the global installations in mind.
      E.g. there is numpy (1.7.1). Could I use that in each Django app, when there is no local NumPy?

      You should not rely on system site packages as your project dependencies. Those packages are there as dependencies of other system software and can change when system software is updated. If they change and are no longer compatible with your project then your site could go down.

      Instead, define your dependencies in a requirements.txt (or whatever config is needed for whatever type of setup you're using) and install them into your project environment.

      Watchduck Let's say I want to use 3.12 for one Django app, but keep the others as they are.
      Can that easily be done?
      (It probably sounds like nothing could go wrong, but on my Ubuntu this was a mess.)

      Sure, if you want to change just one app to use Python 3.12 you can do that. The commands are:

      cd ~/apps/whatever
      mv env env.old
      python3.12 -m venv env
      source scl_source enable devtoolset-11
      source env/bin/activate
      pip install -U pip
      pip install uwsgi
      pip install -r yourproject/requirements.txt # or whatever your build system uses
      Mastodon