APIから返されるjsonをパースするスクリプトを書こうと思ってるんだけど、シェルスクリプトではどうも面倒くさそうだし、いい機会なのでpythonを勉強しつつ書いてみようと思っている。(いい方法あるのかもしれないけど)
pythonのHTTPクライアントはRequestsというのが一般的なようなので、これをつかってみたら早速エラー発生。
インストールされてるものだと思っててすみません。
いや、入っとるやんけ。どうなってんのよとGoogle先生召喚。
さすがのStack Overflow。どうやらPython2.7をインストールしたあとに、2.7バージョンのpipをインストールしてないからだそうです。情弱ですみません・・・。
再度挑戦!
入った!
日々、勉強です。
pythonのHTTPクライアントはRequestsというのが一般的なようなので、これをつかってみたら早速エラー発生。
% python foo.py
Traceback (most recent call last):
File "foo.py", line 4, in
import requests
ImportError: No module named requests
インストールされてるものだと思っててすみません。
% pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/site-packages/requests-1.2.3-py2.7.egg
Cleaning up...
いや、入っとるやんけ。どうなってんのよとGoogle先生召喚。
After you installed Python 2.7, did you install the Python 2.7 version of easy_install and PIP?
via: Can't install module with python-pip properly - Stack Overflow
さすがのStack Overflow。どうやらPython2.7をインストールしたあとに、2.7バージョンのpipをインストールしてないからだそうです。情弱ですみません・・・。
% sudo easy_install pip
Password:
Searching for pip
Reading http://pypi.python.org/simple/pip/
Best match: pip 1.5.1
Downloading https://pypi.python.org/packages/source/p/pip/pip-1.5.1.tar.gz#md5=4678c2ae5cce4e9234c3923d7dcb32f0
Processing pip-1.5.1.tar.gz
Running pip-1.5.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-L_0Nrx/pip-1.5.1/egg-dist-tmp-LiBuef
warning: no files found matching 'pip/cacert.pem'
1 #!/usr/bin/python
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.rst' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Adding pip 1.5.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/pip-1.5.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
再度挑戦!
% sudo pip install requests
Downloading/unpacking requests
Downloading requests-2.2.0-py2.py3-none-any.whl (623kB): 623kB downloaded
Installing collected packages: requests
Successfully installed requests
Cleaning up...
入った!
% python
Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
日々、勉強です。