module ‘pcl’ has no attribute 'PointCloud’与ubuntu18.04安装python-pcl
AttributeError: module 'pcl' has no attribute 'PointCloud'
终端输出:
cloud = pcl.PointCloud()
AttributeError: module 'pcl' has no attribute 'PointCloud'
可能原因之一是:因为没有安装python-pcl
,印象里面本机没有安装python-pcl
pip install pcl
不能解决问题
见下面
参考链接:Ubuntu18.04安装python-pcl
ubuntu18.04``python3.7
,具体环境为之前使用anaconda
配置的yolov5
环境yolov5py37
:https://blog.csdn.net/BIT_HXZ/article/details/123444769
Ubuntu18.04默认安装1.8版本的pcl
输入:sudo apt-get install libpcl-dev pcl-tools
终端打印:libpcl-dev 已经是最新版 (1.8.1+dfsg1-2ubuntu2.18.04.1)。
即已经安装
一般pcl与VTK(visualization toolkit)的对应版本如下(参考vtk编译问题踩坑-Ubuntu16.04编译切换pcl版本):
(1) pcl-1.7.2 vtk-5.10.1 / vtk-6.2.0
(2) pcl-1.8.1 vtk-7.1.1
(3) pcl-1.9.1 vtk-8.2.0
sudo apt-get install libgl1-mesa-dev #需要先安装opengl
sudo apt-get install libxt-dev
终端均输出已经安装
查看之前是否使用源码安装过VTK,一般源码安装的VTK在下面的目录:
/usr/local/include/ #包含目录,头文件所在
/usr/local/lib # 动态库目录
我这里还没有
sudo find | grep "VTK"
打印输出如下,说明系统自带的版本为vtk-6.3
./usr/lib/cmake/vtk-6.3/
............
./usr/lib/python2.7/dist-packages/vtk
............
./usr/include/vtk-6.3/
python
环境,在配置不同python
环境时可能需要单独考虑,见2.4 使用源码方式,安装python-pcl
的修改配置setup.py文件
点击VTK下载网址,依次点击Download the earlier release (7.1.1)
,VTK-7.1.1.tar.gz
tar -xf VTK-7.1.1.tar.gz
cd VTK-7.1.1
mkdir build
cd build && cmake ..
make -j8 #或 make -j16
sudo make install
看终端打印信息,得出安装在
-- Installing: /usr/local/lib/cmake/vtk-7.1/
-- Installing: /usr/local/include/vtk-7.1/
还有一些后缀.so
的库文件
pip list | grep "pcl"
终端打印:pcl 0.0.0.post1
这一步骤很重要,否则后期依旧会报未定义符号的错误,例如我这次使用conda的虚拟环境yolov5py37
,删除pcl
查看pcl
文件地址: pip install pcl
终端打印: Requirement already satisfied: pcl in /home/meng/anaconda3/envs/yolov5py37/lib/python3.7/site-packages (0.0.0.post1)
删除: rm -rf /home/meng/anaconda3/envs/yolov5py37/lib/python3.7/site-packages/pcl/
git clone https://github.com/strawlab/python-pcl.git(原版,如果速度慢请使用下面的)
git clone https://gitee.com/lucy2020/python-pcl.git
修改vtk版本与上面安装vtk的包含目录与库目录,不然会报错cannot find -lvtk****
修改726行为:vtk_version = '7.1'
修改729行为:vtk_include_dir = os.path.join('/usr/local/include/vtk-' + vtk_version)
修改730行为:vtk_library_dir = os.path.join('/usr/local/lib')
修改前如下,指向的是非源码安装的目录,见前面2.3 使用源码方式**安装VTK7.1版本** (2)
的分析
vtk_version = '7.0'
# pcl 1.8.1?
# vtk_version = '8.0'
vtk_include_dir = os.path.join('/usr/include/vtk-' + vtk_version)
vtk_library_dir = os.path.join('/usr/lib')
修改后如下,指向的是源码安装的目录,见前面2.3 使用源码方式**安装VTK7.1版本** (2)
的分析
vtk_version = '7.1'
# pcl 1.8.1?
# vtk_version = '8.0'
vtk_include_dir = os.path.join('/usr/local/include/vtk-' + vtk_version)
vtk_library_dir = os.path.join('/usr/local/lib')
进入python环境yolov5py37
cd /home/meng/Downloads/python-pcl
python setup.py build_ext -i
python setup.py install
终端会打印输出下面类似语句,表示安装在python环境yolov5py37
中了
Installed /home/meng/anaconda3/envs/yolov5py37/lib/python3.7/site-packages/python_pcl-0.3.0rc1-py3.7-linux-x86_64.egg
Processing dependencies for python-pcl==0.3.0rc1