[CentOS] pip を使って Beautifu Soup をインストールする
まず pip を使うのがはじめてなのでどんなオプションがあるのかを確認してみます。
pip は Python のパッケージマネージャですから、yum や apt と似たような使い方ができるようです。
$ pip -h
と叩くとヘルプが表示されます。
show, search, install などお馴染みのオプションを確認することができます。
ではインストールしてみます。root 権限がないと失敗したので sudo を付けて実行しました。
$ sudo pip install beautifulsoup4
[sudo] password for keramax:
Collecting beautifulsoup4
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading beautifulsoup4-4.4.1-py2-none-any.whl (81kB)
100% |████████████████████████████████| 81kB 929kB/s
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.4.1
$
[sudo] password for keramax:
Collecting beautifulsoup4
/usr/lib/python2.6/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
InsecurePlatformWarning
Downloading beautifulsoup4-4.4.1-py2-none-any.whl (81kB)
100% |████████████████████████████████| 81kB 929kB/s
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.4.1
$
なんかいやなエラーが表示されましたが一応インストールできたました。urllib3 を使う時にエラーが出るような気がするのが気になるところ。
Beautiful Soup の動作を確認してみます。
$ python3
Python 3.5.0 (default, Oct 3 2015, 21:27:55)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named ‘bs4’
>>> exit()
$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from bs4 import BeautifulSoup
>>>
Python 3.5.0 (default, Oct 3 2015, 21:27:55)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-11)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named ‘bs4’
>>> exit()
$ python
Python 2.6.6 (r266:84292, Jan 22 2014, 09:37:14)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
>>> from bs4 import BeautifulSoup
>>>
Python 3.5.0 ではうまく使えず 2.6.6 なら動くようです。
あとあと問題が起こりそうな匂いがプンプンしますが、今は考えないでおきます。