A story about a Python beginner who was about to be crushed by ModuleNotFoundError: No module named'tweepy'

Synopsis

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

Convenient commands

** 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.

Synopsis of the solution

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.

Solution path

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

A story about a Python beginner who was about to be crushed by ModuleNotFoundError: No module named'tweepy'
A story about a python beginner stuck with No module named'http.server'
ModuleNotFoundError in Python: No module named story
A story made by a person who has no knowledge of Python or Json
A story about a Python beginner trying to get Google search results using the API
A story about how to specify a relative path in python.
A story about trying to implement a private variable in Python.
A story about a beginner participating in a project by Django from team building to product release in 6 weeks
A story about a person who uses Python addicted to the judgment of an empty JavaScript dictionary
A story about adding a REST API to a daemon made with Python
A story about trying to run multiple python versions (Mac edition)
What to do when ModuleNotFoundError: No module named'XXX' occurs in Python
Python error: ModuleNotFoundError: No module named'flask'
A story about trying to reproduce Katsuwo Isono, who does not react to inconvenience, by natural language processing.
A story about someone who wanted to import django from a python interactive shell and save things to a DB
A story about a beginner making a VTuber notification bot from scratch in Python
A story about a beginner trying hard to set up CentOS 8 (procedure memo)
Today's python error: ModuleNotFoundError: No module named
Today's python error: ModuleNotFoundError: No module named
Today's python error: ModuleNotFoundError: No module named'requests'
A story about Python pop and append
Today's python error: ModuleNotFoundError: No module named'bs4'
Atcoder Beginner Contest A, B Input summary Python that tends to be a problem
A story about a programming beginner who made a business efficiency map application with GeoDjango
Automatic Zakuzaku, Bitcoin. A story about a Python beginner making a coin check 1-minute chart
How to install a Python library that can be used by pharmaceutical companies
I made a module in C language to filter images loaded by Python
A story that I was addicted to when I made SFTP communication with python
ModuleNotFoundError: No module named'_bz2' error in pyenv Python
How to add a Python module search path
A story about running Python on PHP on Heroku
To add a module to python put in Julialang
Import cv2 ModuleNotFoundError: No module named'cv2' in python3
A memo for creating a python environment by a beginner
A story about modifying Python and adding functions
A story about data analysis by machine learning
A story about how Windows 10 users created an environment to use OpenCV3 with Python 3.5
[Python] You can save an object to a file by using the pickle module.
A Python beginner was addicted to registering his own package on PyPI, February 2017 version
A story about trying to introduce Linter in the middle of a Python (Flask) project