2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonでimport requestsが使えなくなった→対処

Posted at

こちらの記事を参考にビットコインのシステムトレードを編集してました。

もっとも初歩的なこちらのコードを書きました

import requests
response = requests.get("https://api.cryptowat.ch/markets/bitflyer/btcjpy/ohlc?periods=86400&after=1514764800")
data = response.json()
print(data)

しかし、説明にあったように、ターミナルでファイルを実行しようとしたら、エラーが出ました。

$ python test.py

Traceback (most recent call last):
  File "test.py", line 9, in <module>
    import requests
ImportError: No module named requests

ちなみにrequestsはインストールしており、jupyter notebookだと上記のコードで実行できます。
スクリーンショット 2019-04-07 14.08.10.png

もくもく会の人に見てもらいまして、python3をつけることで実行できることがわかりました。

$ python3 test.py

あとpipについても、今はpipではエラーが出てpip3だと動きます。

なぜ、以前は"3"をつけずとも実行できたのか、どこで変化が生じたのか不明ですが、とりあえずこれで動くようになったので、もし同様の困りごとの初心者おられれば参考になれば幸いです。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?