For Linux machine, if you have installed pymongo using "pip install pymongo". I would recommend trying to export the PYTHONPATH by appending the site-packages location, like: export PYTHONPATH=$PYTHONPATH:/home/ec2-user/.local/lib/python3.11/site-packages and check again.