Python pcl has no attribute from_array - python

I was trying to run the example on this page:
https://github.com/strawlab/python-pcl/blob/master/examples/example.py
I get the error : AttributeError: type object 'PointCloud' has no attribute 'from_array' on line 49. Also, i cant import few modules like pcl.pcl_visualization and pcl.PointCloud_PointXYZRGB() . Anybody knows how do i slove these issues?
Thanks

You should make sure you aren't running PyPCL by accident. This is an alternate python to PCL binding that import pcl can map to. One way to check this is to run this snippet:
class_names = dict([(name, cls) for name, cls in pcl.__dict__.items() if isinstance(cls, type)])
for name, cls in class_names.items():
print(name)
This will give you a list of classes in the module. If there are two (PointCloud, Quaternion), you likely have PyPCL installed and should uninstall that one. The list of classes in python-pcl returned should look something like this:
PointCloud
PointCloud_PointXYZI
PointCloud_PointXYZRGB
PointCloud_PointXYZRGBA
Vertices
PointCloud_PointWithViewpoint
PointCloud_Normal
PointCloud_PointNormal
KdTree
RangeImages
SampleConsensusModel
SampleConsensusModelPlane
SampleConsensusModelSphere
SampleConsensusModelCylinder
SampleConsensusModelLine
SampleConsensusModelRegistration
SampleConsensusModelStick
Segmentation
Segmentation_PointXYZI
Segmentation_PointXYZRGB
Segmentation_PointXYZRGBA
SegmentationNormal
Segmentation_PointXYZI_Normal
Segmentation_PointXYZRGB_Normal
Segmentation_PointXYZRGBA_Normal
EuclideanClusterExtraction
RegionGrowing
StatisticalOutlierRemovalFilter
StatisticalOutlierRemovalFilter_PointXYZI
StatisticalOutlierRemovalFilter_PointXYZRGB
StatisticalOutlierRemovalFilter_PointXYZRGBA
VoxelGridFilter
VoxelGridFilter_PointXYZI
VoxelGridFilter_PointXYZRGB
VoxelGridFilter_PointXYZRGBA
PassThroughFilter
PassThroughFilter_PointXYZI
PassThroughFilter_PointXYZRGB
PassThroughFilter_PointXYZRGBA
ApproximateVoxelGrid
ApproximateVoxelGrid_PointXYZI
ApproximateVoxelGrid_PointXYZRGB
ApproximateVoxelGrid_PointXYZRGBA
KdTreeFLANN
KdTreeFLANN_PointXYZI
KdTreeFLANN_PointXYZRGB
KdTreeFLANN_PointXYZRGBA
OctreePointCloud
OctreePointCloud_PointXYZI
OctreePointCloud_PointXYZRGB
OctreePointCloud_PointXYZRGBA
OctreePointCloud2Buf
OctreePointCloud2Buf_PointXYZI
OctreePointCloud2Buf_PointXYZRGB
OctreePointCloud2Buf_PointXYZRGBA
OctreePointCloudSearch
OctreePointCloudSearch_PointXYZI
OctreePointCloudSearch_PointXYZRGB
OctreePointCloudSearch_PointXYZRGBA
OctreePointCloudChangeDetector
OctreePointCloudChangeDetector_PointXYZI
OctreePointCloudChangeDetector_PointXYZRGB
OctreePointCloudChangeDetector_PointXYZRGBA
CropHull
CropBox
ProjectInliers
RadiusOutlierRemoval
ConditionAnd
ConditionalRemoval
ConcaveHull
ConcaveHull_PointXYZI
ConcaveHull_PointXYZRGB
ConcaveHull_PointXYZRGBA
MovingLeastSquares
MovingLeastSquares_PointXYZRGB
MovingLeastSquares_PointXYZRGBA
GeneralizedIterativeClosestPoint
IterativeClosestPoint
IterativeClosestPointNonLinear
RandomSampleConsensus
NormalEstimation
VFHEstimation
IntegralImageNormalEstimation
MomentOfInertiaEstimation
HarrisKeypoint3D
NormalDistributionsTransform
Sequence
Alternatively, if you are in a virtual environment you can run pipenv graph to look for this issue. Or:
pip list

Related

YTMUSIC ERROR: 'YTMusic' object has no attribute 'parser'

I've a problem with ytmusicapi. I used it for some tests and was all ok, but now when I search for a song I get this error: 'YTMusic' object has no attribute 'parser'.
Here is a test:
from ytmusicapi import YTMusic
ytmusic = YTMusic()
ric = ytmusic.search("fix you coldplay")
print(ric)
I tried to analyze the script and I created an isoleted one but nothing.
Can you help me?
You are probably using an older version of ytmusicapi. Just update it with pip install -U ytmusicapi and it will work. I tested it on my machine and it works

kubeflow AttributeError: 'ComponentStore' object has no attribute 'uri_search_template'

I am trying to load some prebuit gcp kubeflow components using kfp.components.ComponentStore. However I am getting this error:
line 180, in _load_component_spec_in_component_ref
if self.uri_search_template:
AttributeError: 'ComponentStore' object has no attribute 'uri_search_template'
when at this line of code:
mlengine_train_op = component_store.load_component('ml_engine/train')
KFP version:
kfp 1.8.10
kfp-pipeline-spec 0.1.13
kfp-server-api 1.7.1
Steps to reproduce
import kfp
from kfp.components import func_to_container_op
COMPONENT_URL_SEARCH_PREFIX = "https://raw.githubusercontent.com/kubeflow/pipelines/1.7.1/components/gcp/"
component_store = kfp.components.ComponentStore(
local_search_paths=None, url_search_prefixes=[COMPONENT_URL_SEARCH_PREFIX])
mlengine_train_op = component_store.load_component('ml_engine/train')
mlengine_deploy_op = component_store.load_component('ml_engine/deploy')
I got this code from an example that was running on kfp 0.2.5. This is probably some version problem but does anyone knows how to update this code to the newer version?
I solved the issue. It is something that #Kabilan Mohanraj also mentioned is his comment. It looks like there is a bug if you don't set up uri_search_template when creating the ComponentStore.
I solved it by providing it as parameter, it doesn't really matter what you pass to the constructor really, but it is required because in the code there is the following
if self.url_search_prefixes:
but if you don't pass something that attribute doesn't get created in the constructor.
I fixed it like this:
component_store = kfp.components.ComponentStore(
local_search_paths=["local_search_path"], url_search_prefixes=[COMPONENT_URL_SEARCH_PREFIX]), uri_search_template="{name}/"
I hope it will help someone in the future.
I suggested in the github issue to address this by either make the error more clear or to have better check on uri_search_template attribute.

load_resource function not found as a class method of FPDF

I am looking at the answer to the following question: Insert Base64 image to pdf using pyfpdf
The answer suggested here was to override the existing load_resource method.
What I did instead was
class EnhancedPdf(FPDF):
def load_resource(self, reason, filename):
if reason == "image":
if filename.startswith("data"):
f = filename.split("base64,")[1]
f = base64.b64decode(f)
f = BytesIO(f)
return f
else:
return super().load_resource(reason, filename)
However, Pycharm highlights the super call with the message "Unresolved attribute reference "load_resource" for class "FPDF"
In my command line, I ran the commands
from fpdf import FPDF
dir(FPDF)
Inspecting this list, I see load_resource function is indeed not a listed method. Hence my question is why is the load_resource function not visible?
Most probably you are using Python 3.x where x >= 5 .
On the pypi it says that the module has only experimental support for python 3.y where y <= 4 .
Try it with python 2.7 and it might work.
PS: Better try https://pypi.org/project/fpdf2/, the updated version. For bugs or issues see https://github.com/alexanderankin/pyfpdf .
If you really want to use the old version, you can install whatever version you want from the original repo like this
pip install git+https://github.com/reingart/pyfpdf#<branchname of tag or commit>

Name 'RandomUnderSampler' is not defined

I'm trying to use RandomUnderSampler. I have correctly installed the imblearn module. But still getting the error: "Name 'RandomUnderSampler" is not defined`. Any specific reason for this? Can someone please help
from imblearn.under_sampling import RandomUnderSampler
#Random under-sampling and over-sampling with imbalanced-learn
def random_under_sampling(X,Y):
rus = RandomUnderSampler(return_indices=True)
X_rus, y_rus, id_rus = rus.fit_sample(X, Y)
print('Removed indexes:', id_rus)
plot_2d_space(X_rus, y_rus, 'Random under-sampling')
The actual method name
This is where I called my method
Since it seems that you are using IPython it is important that you execute first the line importing imblearn library (e.g. Ctrl-Enter):
from imblearn.under_sampling import RandomUnderSampler
After that the module should get imported and the name of the function is going to be defined.
If this does not work, could you reload the notebook and execute all the statements up until the random_under_sampling function to ensure nothing was missed?

Gurobi Python Error (NoneType has no len())

I need to write an optimization file for Gurobi (Python) that is a modified version of a classic TSP. I tried to run the example file from their website:
examples.gurobi.com/traveling-salesman-problem/
I always get the following error:
TypeError: object of type 'NoneType' has no len()
What do I need to change?
Thx
Full code: https://www.dropbox.com/s/ewisx805b3o2wq5/beispiel_opt.py?dl=0
I can confirm the error with the example code from Gurobi's website. At the first look the problem seems to be inside the subtour function, that returns None if sum(lengths) == n and the missing check for if tour is None inside the subtourlim function.
Instead of providing a fix for the specific code, I first checked the examples that Gurobi installs inside the specific installation directory:
Mac: /Library/gurobi810/mac64/examples/python/
Linux: /opt/gurobi800/linux64/examples/python/
Windows: c:\gurobi800\win64\examples\python\
And surprisingly the tsp.py from there runs without any errors. Note also that the two mentioned functions are revised. So I guess the example from the website is just a old version of the code.

Categories