今回、仕事でPython3.xでWebスクレイピングを行うことになりました。
以前まで、Python2.xでスクレイピングを行っていましたが、今回は仕事の関係で3.x系を使うことに。
開発環境は手元のMac book air OS X EL Capitan 10.11.3です。
python2.x系では、
$ python Python 2.7.11 |Anaconda custom (x86_64)| (default, Dec 6 2015, 18:57:58) [GCC 4.2.1 (Apple Inc. build 5577)] on darwin Type "help", "copyright", "credits" or "license" for more information. Anaconda is brought to you by Continuum Analytics. Please check out: http://continuum.io/thanks and https://anaconda.org >>> from bs4 import BeautifulSoup >>>
BeautifulSoupを読み込めますが、
$ python3 Python 3.4.3 |Continuum Analytics, Inc.| (default, Mar 6 2015, 12:07:41) [GCC 4.2.1 (Apple Inc. build 5577)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from bs4 import BeautifulSoup Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named 'bs4'
3.xだと読み込めません。
ちなみに、以下でパスを調べてみました。
2系
$python -c "import site; print(site.getsitepackages())" ['Users/heihoo/anaconda/lib/python2.7/site-packages', '/Users/heihoo/anaconda/lib/site-python']
3系
$ python3 -c "import site; print(site.getsitepackages())" ['/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages', '/Library/Frameworks/Python.framework/Versions/3.3/lib/site-python', '/Library/Python/3.3/site-packages']
最後に、pip install beautifulsoup4してみたらいかになります。
$ pip install beautifulsoup4 Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in /usr/local/lib/python2.7/site-packages
pip3コマンドも試してみましたが、ダメでした。
$ pip3 install beautifulsoup4 pyenv: pip3: command not found The `pip3' command exists in these Python versions: 3.4.3
どうすれば、python3系でbeautifulsoup4が使えるようになりますでしょうか?
ご教授宜しくお願い申し上げます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。