Python 3.x 属性错误:模块';bs4和x27;没有属性';美丽集团';
问题是您的文件名是Python 3.x 属性错误:模块';bs4和x27;没有属性';美丽集团';,python-3.x,Python 3.x,问题是您的文件名是bs4.py。现在,如果编写import语句,Python将首先查找具有该名称的本地文件。因此,它假设您的导入bs4引用了您自己的文件。因此,您的文件将以导入自身为目标,但它显然不包含所需的模块 快速修复程序正在重命名文件。例如进入bs4tests.py。然后您可以使用导入bs4 或者,您可以尝试删除本地路径,例如: import bs4 import urllib.request site = urllib.request.urlopen('http://127.0.0.
bs4.py
。现在,如果编写import
语句,Python将首先查找具有该名称的本地文件。因此,它假设您的导入bs4
引用了您自己的文件。因此,您的文件将以导入自身为目标,但它显然不包含所需的模块
快速修复程序正在重命名文件。例如进入bs4tests.py
。然后您可以使用导入bs4
或者,您可以尝试删除本地路径,例如:
import bs4
import urllib.request
site = urllib.request.urlopen('http://127.0.0.1:8000').read()
soup = bs4.BeautifulSoup(site,'lxml')
#for i in site:
# print(site[i])
print(soup)
从bs4导入BeautifulSoup
然后直接使用BeautifulSoup
我认为你不应该给你的文件命名,因为它会引起混乱。
import bs4
import urllib.request
site = urllib.request.urlopen('http://127.0.0.1:8000').read()
soup = bs4.BeautifulSoup(site,'lxml')
#for i in site:
# print(site[i])
print(soup)
import sys # import sys package
old_path = sys.path[:] # make a copy of the old paths
sys.path.pop(0) # remove the first one (usually the local)
import bs4 # import the package
sys.path = old_path # restore the import path