fly logs reveals a psycopg error but I already installed psycopg

I am trying to deploy my blog website for django for beginners.

I am trying to understand what this error message is saying.

(.venv) andrewstribling@Andrews-MBP blog % flyctl deploy
==> Verifying app config
Validating /Users/andrewstribling/Desktop/code/blog/fly.toml
Platform: machines
āœ“ Configuration is valid
--> Verified app config
==> Building image
Remote builder fly-builder-snowy-morning-5375 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 0.5s (12/12) FINISHED                                                                                                                                                                         
 => [internal] load build definition from Dockerfile                                                                                                                                                  0.1s
 => => transferring dockerfile: 32B                                                                                                                                                                   0.1s
 => [internal] load .dockerignore                                                                                                                                                                     0.1s
 => => transferring context: 35B                                                                                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/python:3.11-slim-bullseye                                                                                                                          0.3s
 => [1/7] FROM docker.io/library/python:3.11-slim-bullseye@sha256:52c7a54aa5e5068ce76edaf3f8652a64fb99e378fb89fb0bfbe21a8756d0013c                                                                    0.0s
 => [internal] load build context                                                                                                                                                                     0.1s
 => => transferring context: 38.12kB                                                                                                                                                                  0.1s
 => CACHED [2/7] RUN mkdir -p /code                                                                                                                                                                   0.0s
 => CACHED [3/7] WORKDIR /code                                                                                                                                                                        0.0s
 => CACHED [4/7] COPY requirements.txt /tmp/requirements.txt                                                                                                                                          0.0s
 => CACHED [5/7] RUN set -ex &&     pip install --upgrade pip &&     pip install -r /tmp/requirements.txt &&     rm -rf /root/.cache/                                                                 0.0s
 => CACHED [6/7] COPY . /code                                                                                                                                                                         0.0s
 => CACHED [7/7] RUN python manage.py collectstatic --noinput                                                                                                                                         0.0s
 => exporting to image                                                                                                                                                                                0.0s
 => => exporting layers                                                                                                                                                                               0.0s
 => => writing image sha256:69dbee2cfbee6d47a0f2f47c2b0908ccb5d52872e691dc71fa7c0127c85db7f8                                                                                                          0.0s
 => => naming to registry.fly.io/strikeouts27-dfb-blog:deployment-01H7702HVGBRTJAAQZ9J0RNZEW                                                                                                          0.0s
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/strikeouts27-dfb-blog]
9d644e4172be: Layer already exists 
86209e319064: Layer already exists 
9c731170cf33: Layer already exists 
31a7645f9d36: Layer already exists 
5f70bf18a086: Layer already exists 
6ea18eb9419d: Layer already exists 
9ceb636b589d: Layer already exists 
070c5f83bca9: Layer already exists 
b368d30a5cfe: Layer already exists 
d1e9ee275250: Layer already exists 
8ce178ff9f34: Layer already exists 
deployment-01H7702HVGBRTJAAQZ9J0RNZEW: digest: sha256:de770caa2cb80f5055ae51843bf3ed7471d4e207bc84267961f214df0b73f747 size: 2624
--> Pushing image done
image: registry.fly.io/strikeouts27-dfb-blog:deployment-01H7702HVGBRTJAAQZ9J0RNZEW
image size: 192 MB

Watch your app at https://fly.io/apps/strikeouts27-dfb-blog/monitoring

Updating existing machines in 'strikeouts27-dfb-blog' with rolling strategy
  Machine 148e422c77d689 [app] has state: started
  [1/1] Checking that 148e422c77d689 [app] is up and running
Smoke checks for 148e422c77d689 failed: the app appears to be crashing
Check its logs: here's the last lines below, or run 'fly logs -i 148e422c77d689':
    File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 27, in <module>
      import psycopg2 as Database
  ModuleNotFoundError: No module named 'psycopg2'
  During handling of the above exception, another exception occurred:
  Traceback (most recent call last):
    File "/usr/local/lib/python3.11/site-packages/gunicorn/arbiter.py", line 589, in spawn_worker
      worker.init_process()
    File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 134, in init_process
      self.load_wsgi()
    File "/usr/local/lib/python3.11/site-packages/gunicorn/workers/base.py", line 146, in load_wsgi
      self.wsgi = self.app.wsgi()
                  ^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/gunicorn/app/base.py", line 67, in wsgi
      self.callable = self.load()
                      ^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 58, in load
      return self.load_wsgiapp()
             ^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 48, in load_wsgiapp
      return util.import_app(self.app_uri)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/gunicorn/util.py", line 359, in import_app
      mod = importlib.import_module(module)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 940, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "/code/django_project/wsgi.py", line 16, in <module>
      application = get_wsgi_application()
                    ^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
      django.setup(set_prefix=False)
    File "/usr/local/lib/python3.11/site-packages/django/__init__.py", line 24, in setup
      apps.populate(settings.INSTALLED_APPS)
    File "/usr/local/lib/python3.11/site-packages/django/apps/registry.py", line 116, in populate
      app_config.import_models()
    File "/usr/local/lib/python3.11/site-packages/django/apps/config.py", line 269, in import_models
      self.models_module = import_module(models_module_name)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
    File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
    File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 940, in exec_module
    File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
    File "/usr/local/lib/python3.11/site-packages/django/contrib/auth/models.py", line 3, in <module>
      from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
    File "/usr/local/lib/python3.11/site-packages/django/contrib/auth/base_user.py", line 57, in <module>
      class AbstractBaseUser(models.Model):
    File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 143, in __new__
      new_class.add_to_class("_meta", Options(meta, app_label))
    File "/usr/local/lib/python3.11/site-packages/django/db/models/base.py", line 371, in add_to_class
      value.contribute_to_class(cls, name)
    File "/usr/local/lib/python3.11/site-packages/django/db/models/options.py", line 243, in contribute_to_class
      self.db_table, connection.ops.max_name_length()
                     ^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/django/utils/connection.py", line 15, in __getattr__
      return getattr(self._connections[self._alias], item)
                     ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/django/utils/connection.py", line 62, in __getitem__
      conn = self.create_connection(alias)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/django/db/utils.py", line 193, in create_connection
      backend = load_backend(db["ENGINE"])
                ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/django/db/utils.py", line 113, in load_backend
      return import_module("%s.base" % backend_name)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 29, in <module>
      raise ImproperlyConfigured("Error loading psycopg2 or psycopg module")
  django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 or psycopg module
  [2023-08-07 03:19:10 +0000] [260] [INFO] Worker exiting (pid: 260)
  [2023-08-07 03:19:10 +0000] [261] [INFO] Worker exiting (pid: 261)
  [2023-08-07 03:19:10 +0000] [255] [WARNING] Worker with pid 260 was terminated due to signal 15
  [2023-08-07 03:19:10 +0000] [255] [INFO] Shutting down: Master
  [2023-08-07 03:19:10 +0000] [255] [INFO] Reason: Worker failed to boot.
   INFO Main child exited normally with code: 3
   INFO Starting clean up.
   WARN hallpass exited, pid: 256, status: signal: 15 (SIGTERM)
  2023/08/07 03:19:10 listening on [fdaa:2:8356:a7b:cf99:f138:e0ff:2]:22 (DNS: [fdaa::3]:53)
  [    3.272584] reboot: Restarting system
  machine did not have a restart policy, defaulting to restart
  [    0.034964] PCI: Fatal: No config space access function found
   INFO Starting init (commit: b437b5b)...
   INFO starting statics vsock server
   INFO Preparing to run: `gunicorn --bind :8000 --workers 2 django_project.wsgi` as root
   INFO [fly api proxy] listening at /.fly/api
  2023/08/07 03:19:12 listening on [fdaa:2:8356:a7b:cf99:f138:e0ff:2]:22 (DNS: [fdaa::3]:53)
Error: smoke checks for 148e422c77d689 failed: the app appears to be crashing

I reached out for help and it seems that my requirements.txt file did not contain psycopg at the most recent version. Using pylace I can find the most recent version by searching for it.

Upon putting it in the requirements folder I deleted the dockerfile and the fly.toml. I may not have needed to delete the files I may want to try to run it again. But as I understand it the dockerfile was made with the requirements.txt specifications. Overwriting it did the trick.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.