Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 属性错误:模块';bs4和x27;没有属性';美丽集团';_Python 3.x - Fatal编程技术网

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