Python 导入错误:无法导入名称';美丽之路4';
我知道这个问题在这个网站上被问了很多,但是我已经尝试了所有给出的解决方案,我不知道如何解决这个问题 首先,我使用的是Python 导入错误:无法导入名称';美丽之路4';,python,python-3.x,beautifulsoup,anaconda,Python,Python 3.x,Beautifulsoup,Anaconda,我知道这个问题在这个网站上被问了很多,但是我已经尝试了所有给出的解决方案,我不知道如何解决这个问题 首先,我使用的是windows10计算机,使用的是python3.6。我安装了Anaconda作为我的IDE 我试图用pipinstallBeautifulSoup4安装BeautifulSoup4,但我得到了 已满足要求 答复 我试图运行的代码只是 from bs4 import BeautifulSoup4 to which I get the error: ImportError: can
windows10
计算机,使用的是python3.6
。我安装了Anaconda
作为我的IDE
我试图用pip
installBeautifulSoup4
安装BeautifulSoup4
,但我得到了
已满足要求
答复
我试图运行的代码只是
from bs4 import BeautifulSoup4
to which I get the error: ImportError: cannot import name 'BeautifulSoup4'
The full error is:
runfile('C:/Users/ter/.spyder-py3/untitled1.py', wdir='C:/Users/ter/.spyder-py3')
Traceback (most recent call last):
File "<ipython-input-21-8717178e85e1>", line 1, in <module>
runfile('C:/Users/ter/.spyder-py3/untitled1.py', wdir='C:/Users/ter/.spyder-py3')
File "C:\Users\ter\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
execfile(filename, namespace)
File "C:\Users\ter\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/ter/.spyder-py3/untitled1.py", line 8, in <module>
from bs4 import BeautifulSoup4
ImportError: cannot import name 'BeautifulSoup4'
从bs4导入
我得到错误:ImportError:无法导入名称“BeautifulSoup4”
完全错误是:
运行文件('C:/Users/ter/.spyder-py3/untitled1.py',wdir='C:/Users/ter/.spyder-py3')
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
运行文件('C:/Users/ter/.spyder-py3/untitled1.py',wdir='C:/Users/ter/.spyder-py3')
文件“C:\Users\ter\Anaconda3\lib\site packages\spyder\utils\site\sitecustomize.py”,第705行,在runfile中
execfile(文件名、命名空间)
文件“C:\Users\ter\Anaconda3\lib\site packages\spyder\utils\site\sitecustomize.py”,第102行,在execfile中
exec(编译(f.read(),文件名,'exec'),命名空间)
文件“C:/Users/ter/.spyder-py3/untitled1.py”,第8行,在
从bs4导入到bs4
ImportError:无法导入名称“BeautifulSoup4”
以下是我试图解决此问题的方法:
1.因为我找到的90%的解决方案都是因为有人将文件命名为“bs4.py”,所以我检查了一下。然而,这是我在这台计算机上制作的第一个文件,它的名字刚刚命名为“untitled1.py”。后来(我做的最后一件事)出于沮丧,我从我的计算机上删除了bs4和Beautil的每个实例,问题依然存在,因此另一个名为“bs4”的文件肯定不是问题所在。
bs4
(导入bs4
)。这样做很好,或者至少不会导致任何错误bs4
文件当前位于默认的Anaconda
文件夹中。然后我将CD更改为项目文件的位置,甚至尝试将bs4
、bs4-0.0.1.dist-info
和beautifulsoup4-4.6.3.dist-info
文件复制并粘贴到项目文件目录中。那里没有什么真正的变化pip3
bs4。我不知道这是否必要,但我也这么做了Anaconda
一次和bs4/beautifulsoup
7或8次,包括一些使用pip安装-升级-强制重新安装beautifulsoup4
提前感谢你们能给我的任何帮助 正如@Blender所提到的那样,这只是一个美丽的组合:
from bs4 import BeautifulSoup
html = '''<a href="some_url">next</a>
<span class="class"><a href="another_url">later</a></span>'''
soup = BeautifulSoup(html)
for a in soup.find_all('a', href=True):
print("Found the URL:", a['href'])
以上述代码为例这里没有
BeautifulSoup4
,只是BeautifulSoup4
。
Found the URL: some_url
Found the URL: another_url