我试图解决在Python3中导入模块时出现的一个常见问题。我正在运行OSX10.12.5,并将Python3安装在我的MacBook Air上,并使用崇高文本来编辑和运行我的代码。
当我尝试这个导入时:
from bs4 import BeautifulSoup ...I得到了以下错误:
Traceback (most recent call last):
File "/Users/<myname>/Python/code-python3/Pgm#001", line 5, in <module>
from bs4 import BeautifulSoup
ImportError: No module named 'bs4'我成功地安装了这个PIP,在每次重新安装时,我看到如下:
$ pip install beautifulsoup4
Requirement already satisfied: beautifulsoup4 in ./anaconda/lib/python3.5/site-packages我试过用这样的东西来限定位置:
from ./anaconda/lib/python3.5/site-packages/bs4 import BeautifulSoup...but总是会出现各种语法错误;通常是在第一个'/‘上。
我不是在使用虚拟环境,而是计划阅读这种方法,因为这种配置和设置错误是很浪费时间的。
当我试图在python3中正确地运行这个程序时,我会得到稍微不同的错误:
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/<myname>/anaconda/lib/python3.5/site-packages/bs4/__init__.py", line 30, in <module>
from .builder import builder_registry, ParserRejectedMarkup
File "/Users/<myname>/anaconda/lib/python3.5/site-packages/bs4/builder/__init__.py", line 314, in <module>
from . import _html5lib
File "/Users/<myname>/anaconda/lib/python3.5/site-packages/bs4/builder/_html5lib.py", line 70, in <module>
class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder):
AttributeError: module 'html5lib.treebuilders' has no attribute '_base'任何关于我仍然失踪的明显答案的提示都将不胜感激。我在类似的问题中见过很多关于PATH和PYTHONPATH的东西,但是这些解决方案都没有成功。
发布于 2017-07-04 23:55:36
是的,我不是阿纳康达的粉丝,但看上去这条路是指:
"/Users//anaconda/lib/python3.5/site-packages“
..。并且为了保持尽可能的干净(这是一个很好的例子/原因,为什么你会看到人们说在您的python项目中使用env )
让谷歌在这里!下面是如何删除anaconda:
conda install anaconda-clean #first the configs
anaconda-clean --yes
rm -rf ~/anaconda.* #then conda, the ".*" is regex to cover any version检查您的bash_profile和/或bashrc;这里您可以设置您的Python。确保它没有指向蟒蛇
如果你跑
ls -lh `which python # orpython3您将得到的路径是您将设置为路径的路径。
https://stackoverflow.com/questions/44912182
复制相似问题