I INSTALLED FASTAPI FOUR TIMES AND PYTHON 3.9 STILL CAN'T FIND IT

Solvedpippythonvenv5 replies · 205 views · started
Accepted solution by Ibrahim Mendes — watch out for package name vs import name. pip install python dotenv gives u import dotenv, psycopg2 binary gives import psycopg2, PyYAML…
  1. deploy night... everything passed locally on Python 3.9, so I pushed and let gunicorn pick it up... two seconds later the logs filled with red:

    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 package is right there in site-packages, i can see the folder lmao my teammate says it works on my machine and walked away. im starting to take this personally.

    i already tried pip install --upgrade fastapi and pip install --force-reinstall fastapi. both say success. i even rebooted the box out of desperation. pls tell me theres a logical explanation, because Im out of guseses. pls help 🙏

    10
  2. in Docker, teh classic mistake is installing into one stage of a multi-stage build and copying only teh app into the final stage. either copy the venv over (COPY --from=build /opt/venv /opt/venv and put /opt/venv/bin on PATH) or install in the final stage.

    2 0 helpful
  3. came here to say exactly this. is python even worth bothering with or should i just leave it worked for me anyway 🤷

    4 0 helpful
  4. Accepted solution

    watch out for package name vs import name. pip install python-dotenv gives u import dotenv, psycopg2-binary gives import psycopg2, PyYAML gives import yaml. If you installed a similarly named but different package the import will fail even tho pip is happy. hope that helps :)

    2 2 helpful
  5. oh ive been there lol same issue here on my old thiknpad... drviing me crazy worked for me anyway 🤷

    1 1 helpful
  6. @ibrahim_cipher-w9 wowww ok rebuilt the Docker image copying the venv into teh final stage... logs are clean. I owe this thread a coffee. seriously made my day 😭🙏

    mindblown

    15 2 helpful

Reply to this topic

Sign in or create an account to reply.