cgm@cgm:~/文档/rgbd_benchmark_tools$ /bin/python /home/cgm/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools/evaluate_ate.py
Traceback (most recent call last):
File "/home/cgm/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools/evaluate_ate.py", line 43, in <module>
import numpy
File "/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages/numpy/__init__.py", line 130
raise ImportError(msg) from e
^
SyntaxError: invalid syntax
cgm@cgm:~/文档/rgbd_benchmark_tools$ echo $PYTHONPATH
/opt/ros/noetic/lib/python3/dist-packages:/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
为什么只有两个环境
怎么不使用anaconda3/envs/yolov8这个环境,我是在ubuntu的vscode
我之前一直使用是naconda3/envs/yolov8这个环境,.bashrc文件里:export PYTHONPATH=$PYTHONPATH:/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
Thanks for $PYTHONPATH
the information. The cause of the problem is now clear. $PYTHONPATH
The environment variable specifies the Python module search path, which contains two directories:
/opt/ros/noetic/lib/python3/dist-packages
: This is the Python library path for ROS (Robot Operating System)./home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
: This is the Python 3.8 library path for the Anaconda environment you mentioned earlier.
Because of /home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
this $PYTHONPATH
, the Python 2 environment cannot be completely isolated, as it can still access the Python 3 libraries in the Anaconda environment.
To resolve this issue, you can temporarily $PYTHONPATH
remove . You can use the following command to do this:
方法一:
export PYTHONPATH=/opt/ros/noetic/lib/python3/dist-packages
Then run the Python 2 script:
/bin/python /home/cgm/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools/evaluate_ate.py
This will ensure that the Python 2 environment is not affected by the Anaconda environment, as it will no longer search the Anaconda environment for Python 3 libraries.
Please note that this is only a temporary solution and will need to be executed manually every time before running the script in a Python 2 environment. If you want a more permanent solution, you may want to check the Anaconda environment and system settings more deeply to make sure they don't interfere with the Python 2 environment.
方法二:
If the path to the Anaconda environment appears in $PATH, you can remove it by editing the .bashrc file or the .zshrc file. Find a line similar to the following and delete or comment it out:
export PATH="/home/cgm/anaconda3/envs/yolov8/bin:$PATH"
My .bashrc file
export PYTHONPATH=$PYTHONPATH:/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages:
我最后把.bashrc文件里的这行注释了
@cgm:~$ source .bashrc
cgm@cgm:~$ echo $PYTHONPATH
/opt/ros/noetic/lib/python3/dist-packages
现在就没有这个环境了:/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
注意:
When running evaluate_ate.py
cgm@cgm:~/文档/rgbd_benchmark_tools$ /bin/python /home/cgm/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools/evaluate_ate.py
usage: evaluate_ate.py [-h] [--offset OFFSET] [--scale SCALE]
[--max_difference MAX_DIFFERENCE] [--save SAVE]
[--save_associations SAVE_ASSOCIATIONS] [--plot PLOT]
[--verbose]
first_file second_file
evaluate_ate.py: error: too few arguments
The complete running code requires the first_file true value trajectory and the second_file estimated value trajectory
我创建了一个python2的conda环境
conda create -n python2env python=2.7
conda activate python2env
conda info --envs
pip install matplotlib
(python2env) cgm@cgm:~/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools$ pip install matplotlib
.....................................
(python2env) cgm@cgm:~/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools$ /bin/python evaluate_ate.py rgbd_dataset_freiburg1_360-groundtruth.txt freiburg1_360-rgbdslam.txt --plot output_image.png
0.070789
Traceback (most recent call last):
File "evaluate_ate.py", line 175, in <module>
import matplotlib
ImportError: No module named matplotlib
(python2env) cgm@cgm:~/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools$
Based on your output, you have successfully activated the virtual environment and installed matplotlib in the Python interpreter in the virtual environment, but it still seems to be using Python 2.7 on your system when running the script. This may be because when the virtual environment is activated, you are using /bin/python directly, which may still be pointing to the system's Python 2.7.
要使用虚拟环境中的Python解释器,您可以使用虚拟环境中的python命令,而不是/bin/python。请尝试以下命令来运行脚本:
python evaluate_ate.py rgbd_dataset_freiburg1_360-groundtruth.txt freiburg1_360-rgbdslam.txt --plot output_image.png
这三个文件(evaluate_ate.py rgbd_dataset_freiburg1_360-groundtruth.txt freiburg1_360-rgbdslam.txt)在一个目录下
By running the above command, you should be able to correctly use the matplotlib library and Python interpreter in a virtual environment to generate trajectory images. If the problem persists, make sure the virtual environment is properly activated and the python command is pointing to the Python interpreter in the virtual environment.
(python2env) cgm@cgm:~/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools$ python evaluate_ate.py rgbd_dataset_freiburg1_360-groundtruth.txt freiburg1_360-rgbdslam.txt --plot output_image.png
0.070789
rgbd_benchmark_tools
The contents of this folder
(python2env) cgm@cgm:~/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools$ ls
add_pointclouds_to_bagfile.py generate_pointcloud.py
associate.py generate_registered_pointcloud.py
associate.pyc output_image.png
evaluate_ate.py plot_trajectory_into_image.py
evaluate_rpe.py rgbd_dataset_freiburg1_360-groundtruth.txt
freiburg1_360-rgbdslam.txt
Simple usage:
# python evaluate_ate.py [真实轨迹] [VIO系统估计的估计] --plot [输出图像名称]
python evaluate_ate.py groundtruth.txt pose_output.txt --plot result.png
最后总结:
(python2env) cgm@cgm:~/文档/rgbd_benchmark_tools/src/rgbd_benchmark_tools$ python evaluate_rpe.py rgbd_dataset_freiburg1_360-groundtruth.txt freiburg1_360-rgbdslam.txt --fixed_delta --delta 1.0 --save output_rpe_data.txt --plot output_image.png
0.07933048022129437
1.注释掉.bashrc文件的这一行
export PYTHONPATH=$PYTHONPATH:/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
2.打开终端运行
cgm@cgm:~$ source .bashrc
cgm@cgm:~$ echo $PYTHONPATH
/opt/ros/noetic/lib/python3/dist-packages
cgm@cgm:~$
3.新建pyhton2的conda环境:
conda create -n python2env python=2.7
conda activate python2env
conda info --envs
pip install matplotlib
4.rgbd_benchmark_tools的根目录新建脚本文件build.sh,内容如下:
# conda activate python2env
# 我之前一直使用是naconda3/envs/yolov8这个环境,.bashrc文件里:export PYTHONPATH=$PYTHONPATH:/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
# 解决:注释掉export PYTHONPATH=$PYTHONPATH:/home/cgm/anaconda3/envs/yolov8/lib/python3.8/site-packages
# 然后:source .bashrc
cd src/rgbd_benchmark_tools
python evaluate_ate.py rgbd_dataset_freiburg1_360-groundtruth.txt freiburg1_360-rgbdslam.txt --plot output_ate_image.png
python evaluate_rpe.py rgbd_dataset_freiburg1_360-groundtruth.txt freiburg1_360-rgbdslam.txt --fixed_delta --delta 1.0 --save output_rpe_data.txt --plot output_rpe_image.png
5.把真值文件txt和预计轨迹文件txt放入rgbd_benchmark_tools/src/rgbd_benchmark_tools中,保持和py文件在一个目录(目的是运行命令可以变得很短)
6.cgm@cgm:~/文档/rgbd_benchmark_tools$ chmod +X build
7.cgm@cgm:~/文档/rgbd_benchmark_tools$ conda activate python2env
8.(python2env) cgm@cgm:~/文档/rgbd_benchmark_tools$ ./build.sh
0.070789
0.07933048022129437
9.rgbd_benchmark_tools/src/rgbd_benchmark_tools有生成的2个图片(output_ate_image.png;output_rpe_image.png)和output_rpe_data.txt文件