why does python 3.13 ignore the venv i activated five minutes ago? ๐Ÿค”

pippythonvenv37 replies ยท 747 views ยท started
  1. small Flask-ish API, nothing fancy. I moved it to a new box, created a venv, installed requirements, and hooked it up to gunicorn. instead of a running service I got this traceback:

    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'
    

    The weird part: if I source venv/bin/activate and run it, no error at all, is teh venv only half real?

    Do i need to activate the venv inside teh service somehow? Or copy packages to the system Python? Id rather understand the right way than hack smth together that breaks again next month. im about to throw this thing out the window lol

    cry

    1
  2. oh ive been there lol almost always this is two different interpreetrs. 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 teh unit or script says /usr/bin/python3, it will never see packages from your venv. point it at /path/to/venv/bin/python explicitly.

    25 0 helpful
  3. @ereid_25 thank u this worked!! owe u a beer ๐Ÿบ

    5 0 helpful
  4. ok so came here to say exactly this

    2 2 helpful
  5. is pip even worth bothering with or should i just leave it

    6 0 helpful
  6. lol same thing happened to me have u checked your gunicorn settings? mine were reset after an update

    4 0 helpful
  7. oof bump, still happening with pip for me lmk how it goes

    3 0 helpful
  8. ehh idk man that sounds like bad advice tbh

    37 2 helpful
  9. oof came here to say exactly this fingers crossed ๐Ÿคž

    1 1 helpful
  10. ok but which version are you on?. honestly just reset the extension and save yourself the pain ??

    0 2 helpful
  11. also lol unrelated but anyone elses coffee machine also judging them today :)

    lol

    0 3 helpful
  12. Stop using bare pip. use python -m pip install fastapi with the exact interpreter that runs the app. That way the package lands in the same site-packages that the interpreter searches.

    6 2 helpful
  13. dumb question but how do i even check the power plan, i swear pip is cursed

    2 0 helpful
  14. oof activating a venv only changes PATH in ur 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 teh full path too.

    1 5 helpful

Reply to this topic

Sign in or create an account to reply.