简体   繁体   中英

Python - Import tweepy ImportError: No module named tweepy

I installed pip install tweepy and it installed without errors.

Requirement already satisfied: tweepy in /Library/Python/2.7/site-packages
Requirement already satisfied: requests>=2.11.1 in /Library/Python/2.7/site-packages (from tweepy)
Requirement already satisfied: PySocks>=1.5.7 in /Library/Python/2.7/site-packages (from tweepy)
Requirement already satisfied: six>=1.10.0 in /Library/Python/2.7/site-packages (from tweepy)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /Library/Python/2.7/site-packages (from tweepy)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Python/2.7/site-packages (from requests>=2.11.1->tweepy)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /Library/Python/2.7/site-packages (from requests>=2.11.1->tweepy)
Requirement already satisfied: idna<2.7,>=2.5 in /Library/Python/2.7/site-packages (from requests>=2.11.1->tweepy)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /Library/Python/2.7/site-packages (from requests>=2.11.1->tweepy)
Requirement already satisfied: oauthlib>=0.6.2 in /Library/Python/2.7/site-packages (from requests-oauthlib>=0.7.0->tweepy)

Here is my code:

import tweepy
from tweepy import OAuthHandler

consumer_key = 'consumer_key'
consumer_secret = 'consumer_secret'

access_token = 'access_token'
access_token_secret = 'access_token_secret'

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

public_tweepy.API('Yunus Hatipoglu')

for tweet in public_tweets:
    print(tweet.text)
    analysis = TextBlob(tweet.text)
    print(analysis.sentiment)

As application, I use Pycharm and my operating system is OSX.

python3 --version: Python 3.6.4

When I run my code, I get the following error:

import tweepy

ImportError: No module named tweepy

in PyCharm, Settings -> Project Interpreter -> + -> tweepy -> install package.

By doing above, Tweepy has worked in PyCharm terminal.

On the other hand I installed tweepy by typing python3 -m pip install tweepy

Try Installing though this command:

python3 -m pip install tweepy

I had it installed directly in the Python Folder and it didn't work for me.

After that, I uninstalled using: pip uninstall tweepy at the same prompt.

So, I used Anaconda prompt and after code: pip install tweepy it worked for me.

I hope this is useful.

If you are using ubuntu try: sudo apt install python-pip

and then run: python3 -m pip install tweepy

I hope that helps!

This usually happens where You might using the different python environments in pycharm. Your computer may have different python interpreters as you install pip several times. Try to config the exact python interpreter using the following steps. PyCharm, Settings -> Project Interpreter -> This will show the installed package list and dedicated interpreter at the top right-hand side. Try your right interpreter within the dropdown. 在此处输入图像描述

For Ubuntu 20.04

   pip3 install --user tweepy

if you're using Windows You can do.

pip install tweepy

Alternatively, you may clone it from the github source.

git clone https://github.com/tweepy/tweepy.git
cd tweepy
pip install .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM