背景と私がしたこと:私は Web ページ コンテンツ エクストラクタを書いていますが、HTML ファイルをより適切に解析するには BeautifulSoup4 をインストールする必要があることに気付きました。私の Ubuntu 13.04 マシンには、Python2.7 (システムのデフォルト) と Python3.3.1 の両方がインストールされています。pip
両方で何度か失敗した後、easy_install
「SSL 証明書」の問題が原因で、最後の試行で easy_install を使用して BeautifulSoup4 を最終的にインストールする必要がありました。
しかし:以下の情報からわかるように、私のシステムではeasy_install
BS4 が Python2.7 ディレクトリ ( ) にインストールされているようです。/usr/local/lib/python2.7/dist-packages
Searching for beautifulsoup4
Reading http://pypi.python.org/simple/beautifulsoup4/
Best match: beautifulsoup4 4.2.1
Downloading https://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-4.2.1.tar.gz#md5=91ea70ce16a5f1f43e58f2ef05651679
Processing beautifulsoup4-4.2.1.tar.gz
Writing /tmp/easy_install-OLXNjV/beautifulsoup4-4.2.1/setup.cfg
Running beautifulsoup4-4.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-OLXNjV/beautifulsoup4-4.2.1/egg-dist-tmp-SpupH8
zip_safe flag not set; analyzing archive contents...
Adding beautifulsoup4 4.2.1 to easy-install.pth file
Installed /usr/local/lib/python2.7/dist-packages/beautifulsoup4-4.2.1-py2.7.egg
現在、Python2.7 では BS4 をインポートできますが、Python3.3 ではインポートできず、次のエラー メッセージが表示されます。
>>> import bs4
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import bs4
ImportError: No module named 'bs4'
質問:この Python2.7 ディレクトリを Python3.3 ライブラリ ディレクトリに追加する必要がありますか? (この共有ライブラリ パスが原因で、同じモジュールの異なるバージョンの将来の競合が心配です)、または BS4 をアンインストールして、もう一度試してpip
、Python3.3 ディレクトリに BS4 をインストールする必要がありますか? pip
(現在、 :を使用して BS4 を再度インストールしようとすると、これが返されましたRequirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in ./beautifulsoup4-4.2.1-py2.7.egg
) この問題の解決に関するその他の一般的な指針も高く評価されます。ありがとうございました!