过去一小时我一直在努力安装美味的汤。
我使用以下内容安装但无效
1)下载包 2)转到终端的源文件夹并使用pip setup.py install
进行安装设置成功,我收到写作/Library/Python/2.7/site-packages/beautifulsoup4-4.1.3-py2.7.egg-info
但是当我使用PyCharm导入时,出现以下错误:
from bs4 import BeautifulSoup
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 954, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 896, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1136, in find_spec
File "<frozen importlib._bootstrap_external>", line 1112, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1093, in _legacy_get_spec
File "<frozen importlib._bootstrap>", line 444, in spec_from_loader
File "<frozen importlib._bootstrap_external>", line 530, in spec_from_file_location
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/beautifulsoup4-4.4.0-py3.5.egg/bs4/__init__.py", line 48
'You are trying to run the Python 2 version of Beautiful Soup under Python 3. This will not work.'<>'You need to convert the code, either by installing it (`python setup.py install`) or by running 2to3 (`2to3 -w bs4`).'
^
SyntaxError: invalid syntax
我也尝试过使用python3和2to3来解释使用python3.5。这不应该是问题,因为美丽的汤现在与python 3兼容。
答案 0 :(得分:1)
似乎你安装了错误版本的BeautifulSoup包。
您正在尝试在Python 3下运行Beautiful Soup的Python 2版本
您可以使用pip
pip install beautifulsoup4
或使用easy_install
easy_install beautifulsoup4
或使用已下载binary package
的pip
pip install beautifulsoup4-4.4.1-py3-none-any.whl
您还可以结帐here了解更多详情
希望它有所帮助。
答案 1 :(得分:0)
1)选择项目并按ctrl + Alt + s(打开设置)
2)转到无标题的项目,然后转换为项目翻译
3)单击右侧的+符号以安装所需的包。
来源:https://www.jetbrains.com/pycharm/help/installing-uninstalling-and-upgrading-packages.html