I have a python flask based app, which writes to mongo database.
I am using python 3 with the following requirements.txt
Flask
Jinja2
Werkzeug
certifi
chardet
gunicorn
requests
flask_restful
flask
pymongo
I run into this issue :
Traceback (most recent call last):
File "bin/app.py", line 4, in <module>
from helper import save_message_2_db
File "/app/bin/helper.py", line 1, in <module>
from database import DataAccess, MongoDB
File "/app/bin/database.py", line 1, in <module>
import pymongo
File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/__init__.py", line 83, in <module>
from pymongo.collection import ReturnDocument
File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/collection.py", line 21, in <module>
from bson.code import Code
File "/app/.heroku/python/lib/python3.6/site-packages/bson/code.py", line 19, in <module>
from bson.py3compat import string_type, PY3, text_type
ModuleNotFoundError: No module named 'bson.py3compat'
I am trying to understand why does this happen?
This section is what I am concerned with
File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/__init__.py", line 83, in <module>
from pymongo.collection import ReturnDocument
File "/app/.heroku/python/lib/python3.6/site-packages/pymongo/collection.py", line 21, in <module>
from bson.code import Code
File "/app/.heroku/python/lib/python3.6/site-packages/bson/code.py", line 19, in <module>
from bson.py3compat import string_type, PY3, text_type
ModuleNotFoundError: No module named 'bson.py3compat'
Most of the internet blogs/links tell me bson and pymongo dont play well with eachother. pymongo has its own version of bson and i dont need it in my requirements.txt.
I am looking for help to see why this happens, and how to remidiate this.
Update #1
I was using pymongo-3.5.1, and thats where the problem persists. I just downgraded to pymongo-3.5.0 and the problem vanished.
This means I know the workaround to fix this, but the upstream code/package has some issues which needs fixing.
所有评论(0)