我遇到以下问题。我想实现一个网络爬虫,到目前为止,它可以工作,但速度太慢,所以我尝试使用多重处理来获取 URL。不幸的是我在这个领域不是很有经验。经过一番阅读后,我认为最简单的方法是使用map来自的方法multiprocessing.pool。
但我不断收到以下错误:
TypeError: Pickling an AuthenticationString object is disallowed for security reasons
Run Code Online (Sandbox Code Playgroud)
我发现很少有同样错误的案例,不幸的是它们并没有帮助我。
我创建了代码的精简版本,它可以重现该错误:
import multiprocessing
class TestCrawler:
def __init__(self):
self.m = multiprocessing.Manager()
self.queue = self.m.Queue()
for i in range(50):
self.queue.put(str(i))
self.pool = multiprocessing.Pool(6)
def mainloop(self):
self.process_next_url(self.queue)
while True:
self.pool.map(self.process_next_url, (self.queue,))
def process_next_url(self, queue):
url = queue.get()
print(url)
c = TestCrawler()
c.mainloop()
Run Code Online (Sandbox Code Playgroud)
我将非常感谢任何帮助或建议!
python queue multiprocessing python-3.x python-multiprocessing
我在其中一个张量流教程中运行该示例时遇到了问题.该教程说运行我只需要输入python fully_connected_feed.py.当我这样做时,它会获取输入数据,但随后失败,如下所示:
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
Traceback (most recent call last):
File "fully_connected_feed.py", line 225, in <module>
tf.app.run()
File "/Users/me/anaconda/lib/python2.7/site-packages/tensorflow/python/platform/default/_app.py", line 11, in run
sys.exit(main(sys.argv))
File "fully_connected_feed.py", line 221, in main
run_training()
File "fully_connected_feed.py", line 141, in run_training
loss = mnist.loss(logits, labels_placeholder)
File "/Users/me/tftmp/mnist.py", line 96, in loss
indices = tf.expand_dims(tf.range(batch_size), 1)
TypeError: range() takes at least 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
我认为这个错误是因为会话设置和/或张量评估存在问题.这是导致问题的mnist.py中的函数:
def loss(logits, labels):
"""Calculates the loss from the …Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何相当于
theano.function(inputs=[x,y], # list of input variables
outputs=..., # what values to be returned
updates=..., # “state” values to be modified
givens=..., # substitutions to the graph)
Run Code Online (Sandbox Code Playgroud)
在TensorFlow中
我正在使用 influxdb 尝试'measurements'使用 influxdb v4.0.0 在本地 influxdb 上编写一些内容...
我有点困惑,因为有些地方说你使用 dict 或者你可以使用 json 和/或线路协议......
从这里http://influxdb-python.readthedocs.io/en/latest/examples.html#tutorials-pandas从这里和这里https://github.com/influxdata/influxdb-python/blob/master/influxdb/客户端.py
1st -使用以下命令创建数据库对象:
InfluxDBClient('localhost', database='DBNAME')
Run Code Online (Sandbox Code Playgroud)
第二 -使用数据创建字典:
measurement = {}
measurement['measurement'] = 'energy'
measurement['tags'] = {}
measurement['fields'] = {}
measurement['tags']['MeterID'] = str(meterId)
measurement['fields']['Energy_Wh'] = str(eFrame.getReading())
Run Code Online (Sandbox Code Playgroud)
第三步 -将数据推送到 BD:
try:
self.db.write(measurement)
except Exception as e:
print e
Run Code Online (Sandbox Code Playgroud)
该程序可以运行,但没有数据存储在数据库中,而是我的控制台输出如下:
2017-01-11 12:41:09,741 - INFO - Saving Meter: MeterId = 09060178
u'points'
Meter-ID: 09060178 Energy Value (Wh): 10380300
{'fields': {'Energy_Wh': '10380300'}, 'tags': {'MeterID': …Run Code Online (Sandbox Code Playgroud) 我在 Anaconda3 中创建了一个环境,并在 Linux 机器上安装了 pytorch 和 spyder。以下是规格:
spyder 3.3.1
ipython 7.0.1
python 3.7.0
pytorch 0.4.1
torchvision 0.2.1
Run Code Online (Sandbox Code Playgroud)
当我打开 spyder 并导入 Torch 时,它可以工作。之后我安装了 matplotlib 3.0.1。重新启动 spyder 并再次导入 pytorch 会在 spyder 的 ipython 窗口上显示一条消息:
An error ocurred while starting the kernel
terminate called after throwing an instance of 'std::runtime_error'
what(): expected ) but found 'ident' here:
aten::_addmv(Tensor self, Tensor mat, Tensor vec, *, Scalar beta=1, Scalar alpha=1) ?> Tensor
~~~~~~ <??? HERE
Run Code Online (Sandbox Code Playgroud)
在 bash 终端上,我收到以下消息:
js: Not allowed to load local …Run Code Online (Sandbox Code Playgroud) 据我了解,在Google Colab环境中已预先安装了熊猫。但是它使用的版本不是最新版本。
import pandas as pd
pd.__version__
>>0.22.0
Run Code Online (Sandbox Code Playgroud)
当我想使用安装最新版本时
!pip install pandas==0.23.4
Run Code Online (Sandbox Code Playgroud)
即使日志消息提到0.22.0已成功卸载,它仍使用0.22.0版本而不是新版本。
我应该如何正确升级?
我正在尝试运行以下PyTorch代码:
for i, (input, target) in enumerate(train_loader):
input = input.float().cuda(async=True)
target = target.cuda(async=True)
input_var = torch.autograd.Variable(input)
target_var = torch.autograd.Variable(target)
output = model(input_var)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试时,我收到此错误消息:
input = input.float().cuda(async=True)
^
SyntaxError: invalid syntax
Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我已经安装了cuda。
我正在使用Njissen 在Ubuntu 16.04上的Gaston Frequent Subgraph Mining实现,并在Python 3.6.5和2.7.15rc1上都进行了尝试。执行程序时,我得到一个
Traceback (most recent call last):
File "/home/elias/.local/bin/gaston", line 11, in <module>
load_entry_point('gaston-py==0.1', 'console_scripts', 'gaston')()
File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 484, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2725, in load_entry_point
return ep.load()
File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2343, in load
return self.resolve()
File "/home/elias/.local/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2349, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/gaston.py", line 5, in <module>
import gaston_py.factory as factory
File "/home/elias/.local/lib/python2.7/site-packages/gaston_py/factory.py", line 7, in <module>
import gaston_py.embedding as embedding …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 zip 文件放入 io.BytesIO 缓冲区中,然后提供下载。下面是我得到的内容(较长的views.py的一部分,我只是发布相关部分)。
但我收到以下错误消息:
AttributeError at 'bytes' object has no attribute 'read'
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我做错了什么?
from django.http import HttpResponse
from wsgiref.util import FileWrapper
from zipfile import *
import io
buffer = io.BytesIO()
zipf = ZipFile(buffer, "w")
zipf.write ("file.txt")
zipf.close()
response = HttpResponse(FileWrapper(buffer.getvalue()), content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=file.zip'
return response
Run Code Online (Sandbox Code Playgroud)
编辑:它告诉我错误来自以下行:
response = HttpResponse(FileWrapper(buffer.getvalue()), content_type='application/zip')
Run Code Online (Sandbox Code Playgroud) 作为 pytorch 框架(0.4.1)中的练习,我尝试在简单的线性层(Z = XW + B)中显示 X(gX 或 dSdX)的梯度。为了简化我的玩具示例,我从 Z 之和(不是损失)向后()。
综上所述,我想要 S=sum(XW+B) 的 gX(dSdX)。
问题是 Z (dSdZ) 的梯度为 None。结果,gX 当然也是错误的。
import torch
X = torch.tensor([[0.5, 0.3, 2.1], [0.2, 0.1, 1.1]], requires_grad=True)
W = torch.tensor([[2.1, 1.5], [-1.4, 0.5], [0.2, 1.1]])
B = torch.tensor([1.1, -0.3])
Z = torch.nn.functional.linear(X, weight=W.t(), bias=B)
S = torch.sum(Z)
S.backward()
print("Z:\n", Z)
print("gZ:\n", Z.grad)
print("gX:\n", X.grad)
Run Code Online (Sandbox Code Playgroud)
结果:
Z:
tensor([[2.1500, 2.9100],
[1.6000, 1.2600]], grad_fn=<ThAddmmBackward>)
gZ:
None
gX:
tensor([[ 3.6000, -0.9000, 1.3000],
[ 3.6000, -0.9000, 1.3000]])
Run Code Online (Sandbox Code Playgroud)
如果我使用 …