two pythons, one psycopg2, zero working deploys

pippythonvenv7 replies · 311 views · started
  1. long time lurker first post lol i swear i installed it. pip install psycopg2 finished cleanly, pip list shows it, and when I run the app by hand everything works. Then teh Docker image starts it and I get this:

    PS C:\scripts> python sync_reports.py

    PS C:\scripts> python sync_reports.py
    Traceback (most recent call last):
      File "C:\scripts\sync_reports.py", line 3, in <module>
        import requests
    ModuleNotFoundError: No module named 'requests'
    PS C:\scripts> pip install requests
    Requirement already satisfied: requests in c:\users\...\python311\lib\site-packages
    PS C:\scripts> python sync_reports.py
    ModuleNotFoundError: No module named 'requests'
    

    same server, same repo, same user (I think). ive reinstalled three times and even nuked the venv once. what am I missing?

    For context, this is Python 3.12 on a plain Linux VM, nothing exotic. Im fine at writing Python but environmnets have always felt like dark magic to me. Any poniters on how to see what the service actually sees would be amazing.

    cry

    38
  2. is pydantic the improt name or teh PyPI name?? those dont always match. ??

    thinking

    4 1 helpful
  3. oh ive been there lol almost always this is two different interpreters. compare them directly:

    which python
    python -c "import sys; print(sys.executable)"
    python -m pip --version
    

    Then check what the cron job actually calls. If the unit or script says /usr/bin/python3, it will never see packages from your venv... point it at /path/to/venv/bin/python explicitly. hope that helps :)

    40 0 helpful
  4. Activating a venv only changes PATH in your interactive shell. Services, cron and IDE run configs do not inherit that. For systemd set ExecStart=/opt/app/venv/bin/python app.py (or venv/bin/gunicorn), and for cron use the full path too.

    7 4 helpful
  5. @tess_buffer changed the Docker image to call /opt/app/venv/bin/python directly and it started first try. two interpreters this whole time. thank you!

    6 2 helpful

Reply to this topic

Sign in or create an account to reply.