编译 .pyx 文件工作正常,但当我输入以下内容时突然开始出现错误:
python setup.py build_ext --inplace
Run Code Online (Sandbox Code Playgroud)
我收到错误:
c:\Python27\cython\helloworld>python setup.py build_ext --inplace
running build_ext
cythoning hello.pyx to hello.c
Traceback (most recent call last):
File "setup.py", line 8, in <module>
ext_modules = [Extension("hello", ["hello.pyx"])]
File "C:\Python27\lib\distutils\core.py", line 152, in setup
dist.run_commands()
File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
self.run_command(cmd)
File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
cmd_obj.run()
File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 163,
in run
_build_ext.build_ext.run(self)
File "C:\Python27\lib\distutils\command\build_ext.py", line 340, in run
self.build_extensions()
File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", line 170,
in build_extensions
ext.sources = self.cython_sources(ext.sources, ext)
File "C:\Python27\lib\site-packages\Cython\Distutils\build_ext.py", …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用命名空间解析 XML,XML 看起来像
<DATA xmlns="http://example.com/nspace/DATA/1.0" xmlns:UP="http://example.com/nspace/UP/1.1" col_time_us="14245034321452862">
<UP:IN>...</UP:IN>
<UP:ROW>
<sampleField>...</sampleField>
</UP:ROW>
<UP:ROW>
<sampleField>...</sampleField>
</UP:ROW>
.
.
.
</DATA>
Run Code Online (Sandbox Code Playgroud)
当我使用下面的代码来解析XML时
tree=ET.parse(fileToParse);
root=tree.getRoot();
namespaces = {'UP':'http://example.com/nspace/DATA/1.0'}
for data in root.findAll('UP:ROW',namespaces):
hour+=1
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
AttributeError: 'Element' object has no attribute 'findAll'
Run Code Online (Sandbox Code Playgroud)
当我尝试遍历 root 的子级并打印标签时,我得到的{http://example.com/nspace/DATA/1.0}ROW是标签而不仅仅是 ROWS。
我想找到 ROW 元素并提取 SampleField 标记的值。有人可以指导我我可能做错了什么吗?
我正在使用 python,我需要类中的函数,例如
class asas(object):
def b(self):
self.name = "Berkhan"
a = asas()
a.b().name
Run Code Online (Sandbox Code Playgroud)
我检查这个模块
Traceback (most recent call last):
File "C:\Users\Berkhan Berkdemir\Desktop\new 1.py", line 5, in <module>
a.b().name
AttributeError: 'NoneType' object has no attribute 'name'
Run Code Online (Sandbox Code Playgroud)
我应该怎么办?
当我抓取一个网页时,我总是遇到一个问题。
AttributeError: ResultSet 对象没有属性“查找”。您可能将项目列表视为单个项目。当您打算调用 find() 时,您是否调用了 find_all()?
谁能告诉我如何解决这个问题?我的代码如下:
import requests
r = requests.get('https://www.example.com')
from bs4 import BeautifulSoup
soup = BeautifulSoup(r.text, 'html.parser')
results = soup.find_all('div', attrs={'class':'product-item item-template-0 alternative'})
records = []
for result in results:
name = results.find('div', attrs={'class':'name'}).text
price = results.find('div', attrs={'class':'price'}).text[13:-11]
records.append((name, price,))
Run Code Online (Sandbox Code Playgroud)
我想问一个关闭的问题。如果我想报废多个页面。像下面这样的模式,我使用如下代码,但仍然只报废第一页你能解决这个问题吗?
import requests
for i in range(100):
url = "https://www.example.com/a/a_{}.format(i)"
r = requests.get(url)
from bs4 import BeautifulSoup
soup = BeautifulSoup(r.text, 'html.parser')
results = soup.find_all('div', attrs={'class':'product-item item-template-0 alternative'})
Run Code Online (Sandbox Code Playgroud) 正如标题所说。
当我执行转换后的 python 文件(.exe)时,我得到以下输出:
Traceback (most recent call last):
File "background.py", line 10, in <module>
File "site-packages\praw\reddit.py", line 129, in __init__
File "site-packages\praw\config.py", line 72, in __init__
File "site-packages\praw\config.py", line 98, in _initialize_attributes
File "site-packages\praw\config.py", line 31, in _config_boolean
AttributeError: '_NotSet' object has no attribute 'lower'
[1692] Failed to execute script background
Run Code Online (Sandbox Code Playgroud)
我没有使用 praw.ini 文件,而是将登录值硬编码为:
import praw
import praw.models
import urllib.request
from random import randint
from os import getcwd
import ctypes
r = praw.Reddit(client_id='client',
client_secret='secret',
user_agent='user')
sub = r.subreddit('earthporn')
choose …Run Code Online (Sandbox Code Playgroud) 我想绘制一个堆叠条形图,其中的数据来自 Pandas 中的两个独立数据框(My_means 和 My_stds)。我正在使用 Python 3.7。
绘图调用工作正常,但是,标签被切断。设置 tiny_layout 对我没有帮助,并生成“属性错误:'AxesSubplot' 对象没有属性 'tight_layout'”。这是什么意思,我该如何克服?
我没有发现与此错误相关的任何问题,所以我认为我在做一些相当愚蠢的事情......
这是我的代码:
My_means= ratios.pivot_table('Data', 'Sample ID', 'User ID', aggfunc= np.mean)
My_stds= ratios.pivot_table('Data', 'Sample ID', 'User ID', aggfunc= np.std)
plot_it = My_means.plot(kind='bar', color=stack_cols, stacked=True, yerr=My_stds, capsize=3, title='Just some graph')
plot_it.tight_layout()
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!爵士乐
我有一个看起来像这样的数据框
df
[output]:
date time
2020-02-28 00:30:45
2020-02-28 00:30:45
2020-03-09 00:21:06
2020-03-09 00:21:06
2020-03-09 00:21:06
Run Code Online (Sandbox Code Playgroud)
和
df.time.dtype
[output]: dtype('<m8[ns]')
Run Code Online (Sandbox Code Playgroud)
我想使用以下命令提取时间变量中的分钟数
df.time.dt.minute
Run Code Online (Sandbox Code Playgroud)
但相反,我有这个错误
AttributeError: 'TimedeltaProperties' object has no attribute 'minute'
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决这个问题吗?
我使用的是 Python 3.7,我的编辑器是 PyCharm。当我从 math 模块调用 prod 方法时,它给出了错误:
AttributeError: 模块“math”没有属性“prod”
我该如何解决?(它适用于其他方法,例如floor,sqrt等等。唯一的问题是prod。)
这是我的一段代码:
import math
numbers = [1, 2, 3, 4]
print(math.prod(numbers))
Run Code Online (Sandbox Code Playgroud)
一般来说,我的问题是为什么会出现这个问题,我该如何处理类似的情况?
谢谢。
我试图在 CNN 上实现一个 pytorch 框架。
我确信代码是正确的,因为它来自教程,并且当我在 GoogleDrive 上的 Jupyter Notebook 上运行它时它可以工作。
但是当我尝试将其本地化为.py文件时,它提示一个错误:
AttributeError: Can't pickle local object 'pre_datasets.<locals>.<lambda>'
我知道它是关于函数外部的推断对象,但是这个错误的确切原因是什么?
我应该如何解决它?
这是代码的主要部分。
def pre_datasets():
TRAIN_TFM = transforms.Compose(
[
transforms.Resize(size=(128, 128)),
# TODO
transforms.ToTensor(),
]
)
train_set = DatasetFolder(
root=CONFIG["train_set_path"],
loader=lambda x: Image.open(x),
extensions="jpg",
transform=TRAIN_TFM,
)
train_loader = DataLoader(
dataset=train_set,
batch_size=CONFIG["batch_size"],
shuffle=True,
num_workers=CONFIG["num_workers"],
pin_memory=True,
)
return train_loader
def train(train_loader):
...
for epoch in range(CONFIG["num_epochs"]):
...
for batch in train_loader: # error happened here
...
if __name__ == "__main__":
train_loader = …Run Code Online (Sandbox Code Playgroud) 我正在使用“pdftables”库从 pdf 中提取表格。
这是我的代码:
import pdftables
pg = pdftables.get_pdf_page(open("filename.pdf","rb"),253)
print(pg)
table = pdftables.page_to_tables(pg)
print(table)
Run Code Online (Sandbox Code Playgroud)
我收到此错误,但我不确定是什么原因造成的。
Traceback (most recent call last):
File "c:\Users\gayak\OneDrive\Documents\PDF to Database\PDF_to_Tables_3.py", line 9, in <module>
table = pdftables.page_to_tables(pg)
File "C:\Users\gayak\AppData\Local\Programs\Python\Python310\lib\site-packages\pdftables\pdftables.py", line 485, in page_to_tables
box_list = LeafList().populate(page, flt).purge_empty_text()
File "C:\Users\gayak\AppData\Local\Programs\Python\Python310\lib\site-packages\pdftables\tree.py", line 98, in populate
for obj in children(pdfpage):
File "C:\Users\gayak\AppData\Local\Programs\Python\Python310\lib\site-packages\pdftables\tree.py", line 75, in children
if isinstance(obj, collections.Iterable):
AttributeError: module 'collections' has no attribute 'Iterable'
Run Code Online (Sandbox Code Playgroud)
我使用的python版本是python 3.10.4
我以前pip install pdftables.six去图书馆
attributeerror ×10
python ×9
class ×1
cython ×1
findall ×1
label ×1
layout ×1
matplotlib ×1
namespaces ×1
pdf ×1
pdftables ×1
praw ×1
pycharm ×1
pyinstaller ×1
pytorch ×1
timedelta ×1
xml ×1