zoukankan      html  css  js  c++  java
  • Modify environment variable so that solving Anaconda与ROS共存问题

    when i tried to add a publisher of ROS to a tensorflow python file, i got follow error:

    ImportError: No module named rospkg

    and i found a follow solution Link

    问题描述

    在安装Anaconda后

    $ cd ~/catkin_ws
    $ catkin_make

    编译报错

    ImportError: No module named rospkg

    问题分析

    刚开始以为rospkg出了差错,使用以下命令查错。

    $ sudo apt-get install python-rospkg

    发现rospkg包已经更新到最新版本,那么就基本排除ROS本身Python包出错的可能性。

    又想到,安装Anaconda时有

    Do you wish the installer to prepend the Anaconda2 install location to PATH in your /home/tingting/.bashrc ? [yes|no]

    此处应该是在环境变量中加了什么奇怪的东西影响到ROS的环境变量。为了探究明白,查看环境变量。

    $ echo $PATH

    结果如下

    /home/hanxy/anaconda2/bin:/opt/ros/indigo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

    查看~/.bashrc文件

    $ sudo gedit ~/.bashrc

    发现文件末尾有Anaconda添加的$PATH变量

    $ export PATH=/home/hanxy/anaconda2/bin:$PATH

    解决方法

    初步解决

    想要快速解决很简单,注释掉上述导入环境变量的语句,但同时Anaconda内的包不能正常使用,因此每次开启终端都应该输入上述语句,以获得Anaconda的环境变量。
    但这样在Anaconda中仍然无法使用ROS包,在ROS中也无法使用Anaconda的包,这将是很大的损失。

    彻底解决

    无法在Anaconda中导入ROS包归根结底是由于没有相应的包,因此

    $ conda install setuptools
    $ pip install -U rosdep rosinstall_generator wstool rosinstall six vcstools
    $ hanxy@hanxy-Ubuntu:~$ python
    Python 2.7.14 |Anaconda, Inc.| (default, Oct 16 2017, 17:29:19) 
    [GCC 7.2.0] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import tensorflow
    >>> import rospkg
    >>> 

    同时导入tensorflow和rospkg成功~

    While it did not do much contribution, the publisher worked, but when i roslaunch a moveit related package, the similiar error occured again, it seem you need install other packages in conda environment, so it must not be the right solution.

    Actually, you just need modify the .bashrc file as follow content.

    export PATH="$PATH:/home/robot/anaconda3/bin"

    While it seems these two parts worked perfectly!

  • 相关阅读:
    读取文本文件中的中文打印到Eclipse控制台为何显示问号
    使用StringUtils需要引用的依賴
    Ajax跨域访问XML数据的另一种方式——使用YQL查询语句
    AngularJS快速入门指南15:API
    国外社交网站获取分享数量APIs
    AngularJS快速入门指南14:数据验证
    AngularJS快速入门指南13:表单
    AngularJS快速入门指南12:模块
    AngularJS快速入门指南11:事件
    AngularJS快速入门指南10:DOM节点
  • 原文地址:https://www.cnblogs.com/siahekai/p/11000786.html
Copyright © 2011-2022 走看看