[英]importing beautiful soup in python3
I am trying to import beautifulsoup in python3. 我想在python3中导入beautifulsoup。 I have this line:
我有这条线:
from bs4 import BeautifulSoup
It says: 它说:
from bs4 import BeautifulSoup
File "/usr/local/lib/python2.7/dist-packages/bs4/__init__.py", line 175
except Exception, e:
^
SyntaxError: invalid syntax
I see that it is still trying to use python2.7 package. 我看到它仍在尝试使用python2.7包。 I have installed beautifulsoup for python3 using pip3 and on checking I found that the package is there in /usr/lib/python3/dist-packages/.
我已经使用pip3为python3安装了beautifulsoup,并在检查时发现包中有/ usr / lib / python3 / dist-packages /。
Also on checking sys.path, I found that this path is present. 另外在检查sys.path时,我发现此路径存在。 Still I don't get why it is trying to use the older package,
我仍然不明白为什么它试图使用旧包装,
If python3
executable has python2.7
in sys.path
then it means that the Python 3 installation is broken. 如果
python3
可执行文件在sys.path
有python2.7
,则表示Python 3安装已损坏。
Here's sys.path
on my machine: 这是我机器上的
sys.path
:
['',
'/usr/lib/python3.4',
'/usr/lib/python3.4/plat-x86_64-linux-gnu',
'/usr/lib/python3.4/lib-dynload',
'/home/me/.local/lib/python3.4/site-packages',
'/usr/local/lib/python3.4/dist-packages',
'/usr/lib/python3/dist-packages']
Note: no python2.7
directories. 注意:没有
python2.7
目录。
Make sure PYTHONPATH
is not set, and there are no stray .pth
files in the default list (installation-dependent, above) of Python 3.4 directories that mention python2.7 directories, and PYTHONSTARTUP
file or sitecustomize
, usercustomize
modules do not corrupt sys.path
. 确保
PYTHONPATH
没有设置,并且没有流浪.pth
中提及python2.7目录的Python 3.4的缺省目录列表(取决于安装,以上)文件,和PYTHONSTARTUP
文件或sitecustomize
, usercustomize
模块不会破坏sys.path
。
Perhaps using virtualenv can temporarily solve your problem. 也许使用virtualenv可以暂时解决您的问题。 Or maybe try
pip uninstall beautifulsoup4
That way you're only left with the version pip3 installed. 或者也许尝试
pip uninstall beautifulsoup4
那样你只剩下安装版本pip3了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.