It is a story of a person who could not import tweepy that should have been installed for some reason. It took a whole day to resolve. Probably not solved without teratail. Thank you to all the experts
** pip3 show tweepy
** --- Used in Mac terminal I was able to confirm that it was installed. location
I was able to confirm where it was.
import sys
import pprint
** pprint.pprint (sys.path)
** --- I used these 3 lines in one. If anyone uses it, save it as a python (?) .Py file and run it. You can see where you are referring.
https://qiita.com/kakari8888/items/86d9c255204b063c87ee This article was very helpful.
As a result, I found it in the above pip show tweepy I found that I didn't refer to ** / usr / local / lib / python3.7 / site-packages ** in location, so I put it in the path. I knew immediately where to fix it, but I didn't really know what to fix.
First,
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages')
I was doing endlessly. There is no mistake in this path itself, but this path is ** Reflected only during program execution ** It's a thing. I think it's something that's easy, but I don't realize it. I noticed this, so I combined it with the code to tweet with tweepy.
import sys
sys.path.append('/usr/local/lib/python3.7/site-packages')
#!/usr/bin/env python
# coding:utf-8
#Tweepy import
import tweepy
#Set various keys
CONSUMER_KEY = 'xxxxx'
CONSUMER_SECRET = 'xxxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = 'xxxxx'
ACCESS_TOKEN_SECRET = 'xxxxx'
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
#Create an API instance
api = tweepy.API(auth)
#Fill in the tweet content
api.update_status("Hello World")
Please enter your API for xxxxx of various keys. It's okay if you can tweet Hello World with this. Since this is my first post, it may be unsightly, but I would appreciate it if you could refer to it.
Recommended Posts