pythonpython-3.xflaskitsdangerous

AttributeError: module 'simplejson' has no attribute 'dumps' on "import flask"


On importing the flask module (or any module depending on flask) I get the following error:

Traceback (most recent call last):
  File "main.py", line 2, in <module>
    from flask import Flask, request, render_template, redirect, abort, make_response
  File "/usr/lib/python3.7/site-packages/flask/__init__.py", line 21, in <module>
    from .app import Flask, Request, Response
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 26, in <module>
    from . import cli, json
  File "/usr/lib/python3.7/site-packages/flask/json/__init__.py", line 26, in <module>
    _slash_escape = '\\/' not in _json.dumps('/')
AttributeError: module 'simplejson' has no attribute 'dumps'

My system and package details:

>> uname -r
5.2.3-arch1-1-ARCH
>> pacman -Q --info python-flask
Name            : python-flask
Version         : 1.0.3-1
Description     : Micro webdevelopment framework for Python
Architecture    : any
URL             : http://flask.pocoo.org/
Licenses        : custom:BSD
Groups          : None
Provides        : None
Depends On      : python-werkzeug  python-jinja  python-itsdangerous  python-click
Optional Deps   : None
Required By     : python-flask-wtf
Optional For    : None
Conflicts With  : None
Replaces        : None
Installed Size  : 789.00 KiB
Packager        : Felix Yan <felixonmars@archlinux.org>
Build Date      : Sat 25 May 2019 10:31:00 AM IST
Install Date    : Sun 04 Aug 2019 01:11:45 AM IST
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature


Solution

  • I fixed this by installing simplejson in the map itself (for me /usr/local/Cellar/aws-sam-cli/1.50.0/libexec/lib/python3.8) using this command:

    pip3 install simplejson -t sites-packages