質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

Q&A

解決済

3回答

5847閲覧

pythonでtweepyをimport時にエラーの対応

zero_zero

総合スコア10

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

API

APIはApplication Programming Interfaceの略です。APIはプログラムにリクエストされるサービスがどのように動作するかを、デベロッパーが定めたものです。

0グッド

0クリップ

投稿2020/02/01 21:45

MACのpython3でtweepyを使える様にしたいのですがエラー対応に困っています。
私見では、python3.7.6を使っているのに、「pip install tweepy」でまちがってpython2.7のフォルダーにインストールされてしまっていますが、再インストールもできず、パスの追加も効果が見られず困っています。ご教授頂けると幸いです。

(ターミナルではimportできている様子ですが、VScodeで実行しようとするとエラーになります。)OS再起動しても現象は変わってくれません。
Mac OS : Catalina ver10.15.3

Visual studio code : 1.41.1
--- VScodeのエラーの状況 ----

import tweeps

^^^^^^

に波線がでてインポートされていない表示が出てしまいます。
詳細状況ですが、

ターミナルで
pip show tweepy
のコマンドを叩くと

DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Name: tweepy
Version: 3.8.0
Summary: Twitter library for python
Home-page: http://github.com/tweepy/tweepy
Author: Joshua Roesslein
Author-email: tweepy@googlegroups.com
License: MIT
Location: /Library/Python/2.7/site-packages
Requires: PySocks, requests-oauthlib, six, requests
Required-by:
で正常インストールされている感じです。

ターミナルで
python
のコマンドを叩いて

Python 3.7.6 (v3.7.6:43364a7ae0, Dec 18 2019, 14:18:50)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

import tweepy

のコマンドを叩いてもエラーにならないので正常にインストールされている様です。

そこでpathが通っていないか調べました。


export -p のコマンドを叩くと

declare -x PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/_/Library/Python/2.7/lib/python/site-packages"
でPATHは通っている感じです。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答3

0

sudo pip install tweepy

pip3コマンドはありませんか?

投稿2020/02/02 04:55

technocore

総合スコア7200

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

zero_zero

2020/02/02 05:20

pip3コマンド。あります。 →以下の結果になってしまい、インストールできない状況です。 すみませんがご教授頂けると幸いです。 ------------- > sudo pip install tweepy Requirement already satisfied: tweepy in /Library/Python/2.7/site-packages (3.8.0) Requirement already satisfied: PySocks>=1.5.7 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (1.7.1) Requirement already satisfied: requests-oauthlib>=0.7.0 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (1.3.0) Requirement already satisfied: six>=1.10.0 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from tweepy) (1.12.0) Requirement already satisfied: requests>=2.11.1 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (2.22.0) Requirement already satisfied: oauthlib>=3.0.0 in ./Library/Python/2.7/lib/python/site-packages (from requests-oauthlib>=0.7.0->tweepy) (3.1.0) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (1.25.8) Requirement already satisfied: certifi>=2017.4.17 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (2019.11.28) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (3.0.4) Requirement already satisfied: idna<2.9,>=2.5 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (2.8)
guest

0

>python2.7のフォルダーにインストールされてしまっていますが、再インストールもできず、

アンインストールすればいいのでは?

投稿2020/02/02 03:57

technocore

総合スコア7200

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

zero_zero

2020/02/02 04:14

回答ありがとうございます。 アンインストールして、再インストールしました。 なぜか再インストールしても同じ2.7にインストールされてしまい、vscodeで確認するとtweepyのimportがNGになってしまいます。すみませんがご教授頂けると幸いです。 以下ターミナルでのオペレーション結果です。 > sudo pip install tweepy DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support WARNING: The directory '/Users/hikaru_mini/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. WARNING: The directory '/Users/***_***/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting tweepy Downloading https://files.pythonhosted.org/packages/36/1b/2bd38043d22ade352fc3d3902cf30ce0e2f4bf285be3b304a2782a767aec/tweepy-3.8.0-py2.py3-none-any.whl Requirement already satisfied: PySocks>=1.5.7 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (1.7.1) Requirement already satisfied: requests-oauthlib>=0.7.0 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (1.3.0) Requirement already satisfied: six>=1.10.0 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from tweepy) (1.12.0) Requirement already satisfied: requests>=2.11.1 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (2.22.0) Requirement already satisfied: oauthlib>=3.0.0 in ./Library/Python/2.7/lib/python/site-packages (from requests-oauthlib>=0.7.0->tweepy) (3.1.0) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (1.25.8) Requirement already satisfied: certifi>=2017.4.17 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (2019.11.28) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (3.0.4) Requirement already satisfied: idna<2.9,>=2.5 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (2.8) Installing collected packages: tweepy Successfully installed tweepy-3.8.0 ------- > pip show tweepy DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support Name: tweepy Version: 3.8.0 Summary: Twitter library for python Home-page: http://github.com/tweepy/tweepy Author: Joshua Roesslein Author-email: tweepy@googlegroups.com License: MIT Location: /Library/Python/2.7/site-packages Requires: PySocks, requests-oauthlib, six, requests Required-by:
guest

0

ベストアンサー

質問を全部信じるなら

誤import tweeps
正import tweepy

の間違い


python

1import sys 2print(sys.executable)

を実行してどのPythonを使っているのか/自分が使いたいPythonを使っているのか確認する。


/usr/local/bin/python3 -m pip install tweepy

でインストールできるでしょう。

たぶんpip3コマンドがそこに紐付いていると思いますけど。
(pip3 -Vで確認します)

投稿2020/02/02 00:01

編集2020/02/02 05:29
quickquip

総合スコア11029

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

zero_zero

2020/02/02 03:57

回答ありがとうございます。 実行結果は「/usr/local/bin/python3」でした。 →vscodeでpythonのversionが色々選択可能でしたので(ターミナルと合わせるため)3.7.6を選択したのですが同じエラーでした。  (vscodeでversion2.7ならimportエラーはないもののコードの実行ができなかった。) →改めてターミナルから「pip install tweepy」を打ったところ、以下のメッセージがでてしまいまして3.7.6にインストールできない状況です。 python3.7.6にtweepyをinstallできれば良さそうですが、どうしていいかご教授頂けると幸いです。 (エラ〜メッセージ) Requirement already satisfied: tweepy in /Library/Python/2.7/site-packages (3.8.0) Requirement already satisfied: PySocks>=1.5.7 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (1.7.1) Requirement already satisfied: requests-oauthlib>=0.7.0 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (1.3.0) Requirement already satisfied: six>=1.10.0 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from tweepy) (1.12.0) Requirement already satisfied: requests>=2.11.1 in ./Library/Python/2.7/lib/python/site-packages (from tweepy) (2.22.0) Requirement already satisfied: oauthlib>=3.0.0 in ./Library/Python/2.7/lib/python/site-packages (from requests-oauthlib>=0.7.0->tweepy) (3.1.0) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (1.25.8) Requirement already satisfied: certifi>=2017.4.17 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (2019.11.28) Requirement already satisfied: chardet<3.1.0,>=3.0.2 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (3.0.4) Requirement already satisfied: idna<2.9,>=2.5 in ./Library/Python/2.7/lib/python/site-packages (from requests>=2.11.1->tweepy) (2.8)
zero_zero

2020/02/02 05:43

おかげさまで解決しました。 色々ありがとうございます。とても助かりました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問