'RiakBucket' object has no attribute 'new_binary' - python

As I'm trying to store a PNG image file into my riakBucket. As per https://riak-python-client.readthedocs.io/en/1.5-stable/tutorial.html documentation described here actually using riakBucketObject.new_binary().
But when I'm trying to do this over my system, this error is pop-up:
My python script is :
>>> import riak
>>> myClient = riak.RiakClient(pb_port=8087, protocol='pbc')
>>> photo_bucket = myClient.bucket('photo-bucket')
>>> file_data = open('/home/kamli/Pictures/Store3.png','rb').read()
>>> key = photo_bucket.new_binary('myphoto', data=file_data, content_type='image/png')
But error is :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'RiakBucket' object has no attribute 'new_binary'
System Configuration:
Python version - 2.7.6
Riak Version - 2.2.0

Riak 2.2 has changed since 1.5 and the current method to get a new RiakObject from a bucket is simply using RiakBucket.new() or RiakBucket.new_from_file(). The documentation can be found on their readthedocs website. Look for the version switcher near the bottom to look at documentation for each major release.

In addition to what Aaron3468 said, I would like to mention that the Riak Python Client's version does not match Riak's version. The client is versioned according to semver and the latest release is available here.
Please use the latest documentation.

Related

'UnityEnvironment' object has no attribute 'behavior_spec'

I followed this link to doc to create environment of my own.
But when i run this
from mlagents_envs.environment import UnityEnvironment
env = UnityEnvironment(file_name="v1-ball-cube-game.x86_64")
env.reset()
behavior_names = env.behavior_spec.keys()
print(behavior_names)
Game window pop up and then terminal show error saying
Traceback (most recent call last):
File "index.py", line 6, in <module>
behavior_names = env.behavior_spec.keys()
AttributeError: 'UnityEnvironment' object has no attribute 'behavior_spec'
despite the fact that this is the exact snippet as shown in the documentation.
I created environment by following this (it make without brain) and i was able to train the model by .conf file. Now i wanted to connect to python API.
You need to use stable documents and stable repo( RELEASE_TAGS ) to achieve stable results. Unity ML Agents changes it's syntax every few months so that is problem if you are following master branch.
env.get_behavior_spec(behavior_name: str)
Should solve your problem.
https://github.com/Unity-Technologies/ml-agents/blob/release_2/docs/Python-API.md

Open3d Python, Type error using TriangleMesh.create_from_point_cloud_alpha_shape()

I am trying to use open3d to create an "alphahull" around a set of 3d points using TriangleMesh. However I get a TypeError.
import open3d as o3d
import numpy as np
xx =np.asarray([[10,21,18], [31,20,25], [36,20,24], [33,19,24], [22,25,13], [25,19,24], [22,26,10],[29,19,24]])
cloud = o3d.geometry.PointCloud()
cloud.points = o3d.utility.Vector3dVector(xx)
mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_alpha_shape(pcd=cloud, alpha=10.0)
output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: create_from_point_cloud_alpha_shape(): incompatible function arguments. The following argument types are supported:
1. (pcd: open3d.open3d.geometry.PointCloud, alpha: float, tetra_mesh: open3d::geometry::TetraMesh, pt_map: List[int]) -> open3d.open3d.geometry.TriangleMesh
The error says the object I am passing the function is the wrong type. But when I check the type I get this:
>>print(type(cloud))
<class 'open3d.open3d.geometry.PointCloud'>
Please can someone help me with this error?
Note: A comment on this post Python open3D no attribute 'create_coordinate_frame' suggested it might be a problem with the installation and that a solution was to compile the library from source. So I compiled the library from source. After this ran
make install-pip-package. Though I am not sure it completed correctly because I couldn't import open3d in python yet; see output of installation: https://pastebin.com/sS2TZfTL
(I wasn't sure if that command was supposed to complete the installation, or if you were still required to run pip? After I ran python3 -m pip install Open3d I could import the library in python.)
Bug in bindings of current release (v0.9.0):
https://github.com/intel-isl/Open3D/issues/1621
Fix for master:
https://github.com/intel-isl/Open3D/pull/1624
Workaround:
tetra_mesh, pt_map = o3d.geometry.TetraMesh.create_from_point_cloud(pcd)
mesh = o3d.geometry.TriangleMesh.create_from_point_cloud_alpha_shape(pcd, alpha, tetra_mesh, pt_map)

Attribute error from SoCo class MusicLibrary that documentation appears to say is not an error

I am doing initial exploration in the SoCo module which is a Python API for Sonos. Following the tutorial I do
>>> speakers = soco.discover()
>>> speaker = speakers.pop()
>>> speaker.player_name
'Portable'
>>> speaker.ip_address
'192.168.0.11'
>>> speaker.get_current_transport_info()['current_transport_state']
'STOPPED'
So far, so good. Now, still following the documentation, I do
>>> speaker.music_library.list_library_shares()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'MusicLibrary' object has no attribute 'list_library_shares'
and, sure enough, dir(speaker.music_library) confirms there is no such method.
But the documentation for this class says:
Listing and deleting music library shares
Music library shares are the local network drive shares connected to Sonos, which host the
audio content in the Sonos Music Library.
To list the shares connected to Sonos, use the list_library_shares()
method as follows:
››› device.music_library.list_library_shares()
['//share_host_01/music', '//share_host_02/music']
The result is a
list of network share locations.
Now either the documentation is badly out of step with the version I just downloaded (0.18.1; it says not), or I need another pair of eyes to point out what I am doing wrong.
I asked this question also on the SoCo Google group and this is the answer I got:
This function is not included in v0.18.1, but will be in the upcoming
v0.19 release. It's unintuitive but you need to look at the v0.18.1
documentation at:
http://docs.python-soco.com/en/v0.18.1/api/soco.music_library.html
... not the 'latest' version of the documentation.
I forbear to remark on the wisdom of pointing readers of the Getting Started page in the wrong direction.

Don't understand why this AttributeError: 'Graph' object has no attribute 'merge_one' is occurring

I'm following a tutorial, and I'm using the last python2 (homebrew) with PyCharm (with project interpreter configured) - But I'm stuck in this part:
from py2neo import Graph, Node
graph = Graph()
nicole = Node("Person", name="Nicole")
graph.create(nicole)
graph.delete(nicole)
nicole = graph.merge_one("Person", "name", "Nicole")
Error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Graph' object has no attribute 'merge_one'
I already checked the documentation and it seems that I'm doing everything ok . I tried to uninstall and install last version of py2neo but with no success. How I solve this problem?
Expected behavior: Running that command from the python2 console: If that Person exists don't duplicate it but change its values, if don't exist create it.
I fastly ended up using the version 4 as opposed to 2. So using Graph.merge, solved the problem:
jonh = Node("Person", name="Jonh", age = 21)
graph.create(jonh)
ana = Node("Person", name="Ana", age = 44)
graph.create(ana)
michael = Node("Person", name="Ana", age = 33)
graph.merge(michael, "Person", "name") # So the age of Ana will change to 33, as expected.
For using the commands related to my question, the version 2 must be installed, for eg. directly from py2neo repo:
pip install https://github.com/technige/py2neo/archive/release/2.0.7.zip
From inspecting the source code, I think the function you're looking for is Graph.match_one. There is also a function Graph.merge, but that doesn't take Node as an argument.

error xlPrimary not defined in Python win32com

I keep getting errors where xlCategory, xlValue and xlPrimary are not recognised in my python script.
I am trying to label the axes of my graph and was successfully doing so yesterday with this code:
chart = excel.Charts.Add()
chart.Name = "Chart Title"
chart.ChartType = -4169 #xlXYScatter
chart.SetSourceData(firstSheet.Range("$A:$B"))
series = chart.SeriesCollection(1)
series.Name = "Series Name"
chart.Axes(win32com.client.constants.xlCategory).HasTitle = True
chart.Axes(win32com.client.constants.xlCategory).AxisTitle.Caption = "x Axis"
chart.Axes(win32com.client.constants.xlValue).HasTitle = True
chart.Axes(win32com.client.constants.xlValue).AxisTitle.Caption = "y Axis"
This produced the following error:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
startGraphBuild()
File "C:\Python33\InCAS_Study_Analysis\VMDvsMODVMDG.py", line 33, in startGraphBuild
chart.Axes(win32com.client.constants.xlCategory).HasTitle = True
File "C:\Python33\lib\site-packages\win32com\client\__init__.py", line 170, in
__getattr__
raise AttributeError(a)
AttributeError: xlCategory
So I tried this from this stackoverflow question changing axis labels in excel 2007 charts using python win32com:
pAxis = chart.Axes(AxisGroup = xlPrimary)
xAxis = pAxis(1)
yAxis = pAxis(2)
xAxis.HasTitle = True
yAxis.HasTitle = True
xAxis.AxisTitle.Caption = "VMD"
yAxis.AxisTitle.Caption = "MOD VMD"
But this produced the following error:
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
startGraphBuild()
File "C:\Python33\InCAS_Study_Analysis\VMDvsMODVMDG.py", line 37, in startGraphBuild
pAxis = chart.Axes(AxisGroup = xlPrimary)
NameError: global name 'xlPrimary' is not defined
Has anyone else experienced this? Since it was working yesterday I have tried restarting everything, uninstalling and reinstalling pyWin but these haven't worked.
I am using Python 3.3 and Excel 2010.
The constants are defined. However, they will only be loaded if you have created the COM Type Library for the COM objects of interest. There are several ways to do that (my self-answer to Accessing enumaration constants in Excel COM using Python and win32com has some links you'll find useful). But basically try this:
Python 2.7.5 (default, May 15 2013, 22:43:36) [MSC v.1500 32 bit (Intel)] on win
Type "help", "copyright", "credits" or "license" for more information.
Portable Python >>> import win32com
Portable Python >>> win32com.__gen_path__ # path to COM typelib generated by win32com
'C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\gen_py\\2.7'
Now try with Dispatch:
Portable Python >>> from win32com import client
Portable Python >>> xl=client.Dispatch('Excel.Application')
Portable Python >>> client.constants.xlPrimary
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "G:\Portable Python 2.7.5.1\App\lib\site-packages\win32com\client\__init_
__getattr__
raise AttributeError(a)
AttributeError: xlPrimary
Now use EnsureDispatch from gencache:
Portable Python >>> xl=client.gencache.EnsureDispatch('Excel.Application')
Portable Python >>> client.constants.xlPrimary
1
Portable Python >>>
You only need to use EnsureDispatch once, since once the Type library has been created, even Dispatch will load the constants.
If you need to clear the cache for whatever reason, wasn't easy to find, but you can remove the gen_py folder, its path can be found from win32com.__gen_path__.
The main reason for this attribute error is because your COM-server has shifted from late-binding (dynamic) to early binding (static).
In Late Binding, whenever a method is called, the object is queried for the method and if it succeeds, then the call can be made.
In Early Binding, the information of the object model is determined in advance from type information supplied by the object call. Early binding makes use of MakePy. Also, early binding is case sensitive.
There are two ways to fix this issue:
Use the dynamic module to force your code to work in a late-bound oriented way. Example use:
"win32com.client.dynamic.Dispatch()" instead of "win32com.client.Dispatch()"
Use camelcase sensitive keywords for the early bound oriented way. Example use:
"excel.Visible()" instead of "excel.VISIBLE()" or "excel.visible()"
If you want to use variables without case sensitive issues, you should delete the gen_py folder and use win32com.client.Dispatch()

Categories

Resources