12
#!/usr/bin/env python
# encoding: utf-8

import tweepy #https://github.com/tweepy/tweepy
import json as simplejson


    #write tweet objects to JSON
    file = open('tweet.json', 'wb') 
    print ("Writing tweet objects to JSON please wait...")
    for status in alltweets:
        json.dump(status._json,file,sort_keys = True,indent = 4)

    #close the file
    print ("Done")
    file.close()

if __name__ == '__main__':
    #pass in the username of the account you want to download
    get_all_tweets("@AlertZaAfrica")

The python compiler says line 54 is wrong. I already defined import json as simplejson. The above area where I defined import json is showed above.

rabeshi1010
  • 145
  • 1
  • 1
  • 8

1 Answers1

24

You should at first install simplejson to your system to be able to import it:

$ sudo pip3 install simplejson

Then in your code you are now able to import it:

import simplejson as json

From now on you will be able to access simplejson package using json.

Please note, if you're still using python 2 - despite this is not the OPs original question - you should do a

$ sudo pip install simplejson

instead.

ferdy
  • 7,366
  • 3
  • 35
  • 46
  • 1
    I installed it, but still my python is not finding it. – ScottyBlades Apr 09 '20 at 00:51
  • @ScottyBlades I guess, your system python is not version 3. Since the question here is about python3, you might should do a simple pip install simplejson instead, so your system python, which is probably version 2, installs thje simplejson package. HTH – ferdy Apr 09 '20 at 07:41