Sayan Sil
Sayan Sil

Reputation: 6095

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 <[email protected]>
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

Upvotes: 1

Views: 1105

Answers (2)

Tflambre
Tflambre

Reputation: 26

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

Upvotes: 1

Sayan Sil
Sayan Sil

Reputation: 6095

I fixed the issue by editing the said file /usr/lib/python3.7/site-packages/flask/json/__init__.py

Changing line 21 from

from itsdangerous import json as _json

To

import json as _json

This shouldn't be the right way of solving this, so I will wait for the right answer and use this fix for now.

Upvotes: 1

Related Questions