Following the examples on https://networkx.github.io/documentation/stable/reference/drawing.html, I tried the following code:
import networkx as nx
G = nx.complete_graph(5)
A = nx.nx_agraph.to_agraph(G)
H = nx.nx_agraph.from_agraph(A)
I get a RuntimeError as follows:
H = nx.nx_agraph.from_agraph(A)
Traceback (most recent call last):
File "/home/nom/anaconda3/envs/wcats/lib/python3.7/site-packages/pygraphviz/agraph.py", line 1750, in iteritems
ah = gv.agnxtattr(self.handle, self.type, ah)
StopIteration: agnxtattr
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<ipython-input-10-19c378da806e>", line 1, in <module>
H = nx.nx_agraph.from_agraph(A)
File "/home/nom/anaconda3/envs/wcats/lib/python3.7/site-packages/networkx/drawing/nx_agraph.py", line 85, in from_agraph
N.graph.update(A.graph_attr)
File "/home/nom/anaconda3/envs/wcats/lib/python3.7/site-packages/pygraphviz/agraph.py", line 1740, in keys
return list(self.__iter__())
File "/home/nom/anaconda3/envs/wcats/lib/python3.7/site-packages/pygraphviz/agraph.py", line 1743, in __iter__
for (k, v) in self.iteritems():
RuntimeError: generator raised StopIteration
This error is so basic that I suspect there's a problem with the package itself. Any suggestions on how I can try to troubleshoot this one?
Related
I want to image classification with pyspark but
spark_model = sparkdn.fit(train)
gives
PythonException:
An exception was thrown from the Python worker. Please see the stack trace below.
Traceback (most recent call last):
File "/home/esra/anaconda3/envs/env/lib/python3.9/site-packages/sparkdl/image/imageIO.py", line 158, in resizeImageAsRow
imgAsArray = imageStructToArray(imgAsRow)
File "/home/esra/anaconda3/envs/env/lib/python3.9/site-packages/sparkdl/image/imageIO.py", line 121, in imageStructToArray
imType = imageType(imageRow)
File "/home/esra/anaconda3/envs/env/lib/python3.9/site-packages/sparkdl/image/imageIO.py", line 111, in imageType
return sparkModeLookup[imageRow.mode]
KeyError: 0
Any suggestion? Thanks
I'm trying to use a cairo.TeeSurface (pycairo version '1.21.0') to redirect input to multiple surfaces, but I cannot make it work, here is my code:
>>> import cairo
>>> s1 = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500,500)
>>> s2 = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500,500)
>>> s3 = cairo.ImageSurface(cairo.FORMAT_ARGB32, 500,500)
>>> s = cairo.TeeSurface(s1)
>>> s.add(s2)
>>> s.add(s3)
>>> c = cairo.Context(s)
After above iniziatilation if I try to draw a line I get an error:
>>> c.rel_line_to(100,100)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cairo.Error: no current point defined
I tried to set explicitly a point but I get the same error:
>>> c.move_to(10,10)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cairo.Error: no current point defined
For sure I must have misunderstood something, any clue would be appreciated.
I am trying to get the expected value of a NumPy array but I am running into a problem when I pass my array into the function here is an example of what is happening:
a = np.ones(10)
stats.rv_continuous.expect(args=a)
I get this error:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
stats.rv_continuous.expect(args=a)
TypeError: expect() missing 1 required positional argument: 'self'
If I try stats.rv_continuous.expect(a) , I get this error:
'numpy.ndarray' object has no attribute '_argcheck'
Can someone tell me how to get scipy.stats to work with an array?
update:
following bob's comment I changed the code to:
st=stats.rv_continuous()
ev = st.expect(args=signal_array)
print(ev)
where signal_array is a numpy array. However I now get this error:
Traceback (most recent call last):
File "C:\Users\...\OneDrive\Área de Trabalho\TickingClock\Main.py", line 35, in <module>
ev = st.expect(args=signal_array)
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 2738, in expect
vals = integrate.quad(fun, lb, ub, **kwds)[0] / invfac
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\integrate\quadpack.py", line 351, in quad
retval = _quad(func, a, b, args, full_output, epsabs, epsrel, limit,
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\integrate\quadpack.py", line 465, in _quad
return _quadpack._qagie(func,bound,infbounds,args,full_output,epsabs,epsrel,limit)
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 2722, in fun
return x * self.pdf(x, *args, **lockwds)
File "C:\Users\...\AppData\Local\Programs\Python\Python39\lib\site-packages\scipy\stats\_distn_infrastructure.py", line 1866, in pdf
args, loc, scale = self._parse_args(*args, **kwds)
TypeError: _parse_args() got multiple values for argument 'loc'
I am using pymongo to subset a collection in mongodb, I am having problems with the syntax of the query, this is my query:
import pymongo
client=pymongo.MongoClient("localhost",27017)
db=client("publications")
collec=db("zikaVirus2")
pipeline=db.collec.aggregate([
{"$match":{"fullText":{"$exists": "true"}}},
{"$out": "pub_fulltext"}
])
db.pub_fulltext.aggregate(pipeline)
I am getting this error:
Traceback (most recent call last):
File "genColFulltext.py", line 3, in <module>
db=client("publications")
TypeError: 'MongoClient' object is not callable
UPDATE 1
If I do
import pymongo
client=pymongo.MongoClient("localhost",27017)
db=client.publications
collec=db.zikaVirus2
pipeline=db.collec.aggregate([
{"$match":{"fullText":{"$exists": "true"}}},
{"$out": "pub_fulltext"}
])
db.pub_fulltext.aggregate(pipeline)
I get
Traceback (most recent call last):
File "genColFulltext.py", line 11, in <module>
db.pub_fulltext.aggregate(pipeline)
File "/home/danielo/.local/lib/python3.5/site-packages/pymongo /collection.py", line 2397, in aggregate
**kwargs)
File "/home/danielo/.local/lib/python3.5/site-packages/pymongo/collection.py", line 2242, in _aggregate
common.validate_list('pipeline', pipeline)
File "/home/danielo/.local/lib/python3.5/site-packages/pymongo/common.py", line 428, in validate_list
raise TypeError("%s must be a list" % (option,))
TypeError: pipeline must be a list
UPDATE 2
This code runs without problems, but it make nothing of his purpose, the collection pub_fulltext have anything, when it should have data.
import pymongo
client=pymongo.MongoClient("localhost",27017)
db=client.publications
collec=db.zikaVirus2
pipeline=db.collec.aggregate([
{"$match":{"fullText":{"$exists": "true"}}},
{"$out": "pub_fulltext"}
])
for item in pipeline:
db.pub_fulltext.aggregate(item)
Then I try this:
import pymongo
client=pymongo.MongoClient("localhost",27017)
db=client.publications
collec=db.zikaVirus2
pipeline=[db.collec.aggregate([
{"$match":{"fullText":{"$exists": "true"}}},
{"$out": "pub_fulltext"}
])]
for item in db.collection.aggregate(pipeline):
db.collection.aggregate(item)
Getting this error:
Traceback (most recent call last):
File "genColFulltext.py", line 10, in <module>
for item in collection.aggregate(pipeline):
Traceback (most recent call last): File "genColFulltext.py", line 10, in <module>
for item in db.collection.aggregate(pipeline): File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 2397, in aggregate
**kwargs) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/collection.py", line 2304, in _aggregate
client=self.__database.client) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 584, in command
self._raise_connection_failure(error) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 745, in _raise_connection_failure
raise error File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/pool.py", line 579, in command
unacknowledged=unacknowledged) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/network.py", line 114, in command
codec_options, ctx=compression_ctx) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pymongo/message.py", line 679, in _op_msg
flags, command, identifier, docs, check_keys, opts) bson.errors.InvalidDocument: Cannot encode object: <pymongo.command_cursor.CommandCursor object at 0x1008e4198>
I've got an error when I'm using passthru() to call a python script (using subprocess and pipe) with PHP.
Here is the error:
Traceback (most recent call last):
File "…/Desktop/h.py", line 11, in stdout=subprocess.PIPE)
#set up the convert command and direct the output to a pipe
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 593, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/subprocess.py", line 1079, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
The PHP passthru:
<?php
passthru("/usr/bin/python2.5 /Users/Nagar/Desktop/h.py $argument1 $argument2 1 2>&1");
?>
My Python line which cause the error:
p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE) #set up the convert command and direct the output to a pipe
How to use stdout=subprocess.PIPE properly in the subprocess?
Looking forward your answers.
It looks like your PATH doesn't have the directory including the "convert" command. Try replacing:
p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE)
with:
p1 = subprocess.Popen(['/full/path/to/convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE)
where "/full/path/to/convert" might be something like "/usr/bin/convert".
It's because it needs to be executed through a shell, so you need to set shell argument to True:
p1 = subprocess.Popen(['convert', fileIn, 'pnm:-'], stdout=subprocess.PIPE, shell=True)convert command and direct the output to a pipe