pymongo import errors in python3 flask application

sudhishkr

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.

c11o

It might be some package misconfiguration going on. If the bson package is from the mongo-python-driver, which is likely, since in line 19, the import statement from bson.py3compat import string_type, PY3, text_type is present.

However the file py3compat.py seems to be missing, which should be right next to code.py in the bson path.

Update

After the question's update letting us know a downgrade fixed the issue and inspecting the code changes between both versions, no relevant changes to the issue are identifiable. Therefore it even more so suggests there was something wrong with the modules, what exactly is hard to tell.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python-flask handling application errors

From Dev

Import Error in flask application

From Dev

Flask and Flask-SocketIO integration and import errors

From Dev

Calling Python Eve from an Flask application leads to weird errors

From Dev

import skimage not a Valid Win32 application python3

From Dev

Various errors in Python Flask

From Dev

Python 3 idiomatic import with Flask

From Dev

Import issues Python3: import from package for flask project with api modules

From Dev

Flask-PyMongo not working with Python2.7

From Java

python flask import error

From Dev

Flask Celery Python import

From Dev

Python import module not found errors

From Dev

Angstrom Python errors on import io

From Dev

Mongodb pymongo errors DocumentTooLarge

From Dev

Python flask application throws the following error on start ImportError: Import by filename is not supported

From Dev

Python flask application login

From Dev

Flask Pymongo exception management

From Dev

import error when unit testing flask application with nmslib

From Dev

Flask structure -- can't import application from __init__.py

From Mysql

Flask web application - struggling to import user submitted information to MySQL database

From Dev

How to import slider values from a html form to flask application

From Dev

Internal server error in flask application when I try to import pandas

From Dev

change in import in python3

From Dev

Import module in python3

From Dev

Python Flask - Errors after creating a new project

From Dev

Catching Import errors and Name errors in Python during "compile" time

From Dev

Import directory errors with Python 3.5 and above

From Dev

How to fix python module import errors in jenkins

From Dev

Python Import Errors: No module named <myPackage>

Related Related

  1. 1

    python-flask handling application errors

  2. 2

    Import Error in flask application

  3. 3

    Flask and Flask-SocketIO integration and import errors

  4. 4

    Calling Python Eve from an Flask application leads to weird errors

  5. 5

    import skimage not a Valid Win32 application python3

  6. 6

    Various errors in Python Flask

  7. 7

    Python 3 idiomatic import with Flask

  8. 8

    Import issues Python3: import from package for flask project with api modules

  9. 9

    Flask-PyMongo not working with Python2.7

  10. 10

    python flask import error

  11. 11

    Flask Celery Python import

  12. 12

    Python import module not found errors

  13. 13

    Angstrom Python errors on import io

  14. 14

    Mongodb pymongo errors DocumentTooLarge

  15. 15

    Python flask application throws the following error on start ImportError: Import by filename is not supported

  16. 16

    Python flask application login

  17. 17

    Flask Pymongo exception management

  18. 18

    import error when unit testing flask application with nmslib

  19. 19

    Flask structure -- can't import application from __init__.py

  20. 20

    Flask web application - struggling to import user submitted information to MySQL database

  21. 21

    How to import slider values from a html form to flask application

  22. 22

    Internal server error in flask application when I try to import pandas

  23. 23

    change in import in python3

  24. 24

    Import module in python3

  25. 25

    Python Flask - Errors after creating a new project

  26. 26

    Catching Import errors and Name errors in Python during "compile" time

  27. 27

    Import directory errors with Python 3.5 and above

  28. 28

    How to fix python module import errors in jenkins

  29. 29

    Python Import Errors: No module named <myPackage>

HotTag

Archive