pyros-dev / rostful

A lightweight package for providing and consuming ROS services, actions, and topics as RESTful web services
69 stars 41 forks source link

Can't install and use rostful #77

Open dkurzaj opened 8 years ago

dkurzaj commented 8 years ago

Hello, it's been two days since I've been trying to use rostful, but I can't make it... Here is the series of commands I've been running in order to avoid all the error messages I encountered, but it's still not enough:

sudo apt-get install python-pip
sudo apt-get install virtualenvwrapper
echo "source /etc/bash_completion.d/virtualenvwrapper" >> ~/.bashrc

cd ~/catkin_ws/src
git clone --recursive https://github.com/asmodehn/rostful.git

mkvirtualenv rostfulenv --no-site-packages
workon rostfulenv

cd ~/catkin_ws/src/rostful
pip install catkin-pkg

cd ~/catkin_ws/src/rostful/deps
git clone --recursive https://github.com/asmodehn/pyros.git
cd ~/catkin_ws/src/rostful/deps/pyros
pip install .
cd ~/catkin_ws/src/rostful/
pip install .

pip install mock
pip install simplejson
pip install tornado
pip install protobuf
pip install rospkg

When I try to run: python -m rostful flask I get:

Usage: __main__.py [OPTIONS] COMMAND [ARGS]...

Error: No such command "flask".

And when I run: roslaunch rostful rostful.launch I get:

+ python -tt -m rostful run -p 8080 -s flask '--ros-arg=~connections_list:=/rocon/connection_cache/list' '--ros-arg=~connections_diff:=/rocon/connection_cache/diff' --ros-arg=__name:=rostful --ros-arg=__log:=/home/dkurzaj/.ros/log/92e87824-3c5a-11e6-aa36-64006a5f3285/rostful-1.log
WARNING:root: => Emulating ROS setup now for distro indigo and workspaces ()
WARNING:root:Appending path /opt/ros/indigo/stacks to ROS_PACKAGE_PATH
WARNING:root:Appending path /opt/ros/indigo/share to ROS_PACKAGE_PATH
WARNING:root:Appending path /opt/ros/indigo/bin to PATH
WARNING:root:Appending path /opt/ros/indigo/lib to LD_LIBRARY_PATH
WARNING:root:Appending path /opt/ros/indigo/lib/pkgconfig to PKG_CONFIG_PATH
WARNING:root:Prepending path /opt/ros/indigo/lib/python2.7/dist-packages to PYTHONPATH
WARNING:root: => ROS setup emulation done.
WARNING:root:Error: Could not import PyrosROS from .rosinterface.pyros_ros cannot import name core
WARNING:root:Setting up pyros ROS node...
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/dkurzaj/catkin_ws/src/rostful/rostful/__main__.py", line 68, in <module>
    cli()
  File "/home/dkurzaj/catkin_ws/src/rostful/deps/click/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/home/dkurzaj/catkin_ws/src/rostful/deps/click/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/home/dkurzaj/catkin_ws/src/rostful/deps/click/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dkurzaj/catkin_ws/src/rostful/deps/click/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dkurzaj/catkin_ws/src/rostful/deps/click/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/home/dkurzaj/catkin_ws/src/rostful/rostful/__main__.py", line 65, in run
    rostful_server.launch(host, port, list(ros_args), server_type)
  File "/home/dkurzaj/catkin_ws/src/rostful/rostful/server.py", line 68, in launch
    with pyros_ctx_impl(name='rostful', argv=ros_args, base_path=os.path.join(os.path.dirname(__file__), '..', '..', '..')) as node_ctx:
  File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/home/dkurzaj/.virtualenvs/rostfulenv/local/lib/python2.7/site-packages/pyros/pyros_ctx_server.py", line 42, in pyros_ctx
    subproc = PyrosROS(name, argv, base_path=base_path)
UnboundLocalError: local variable 'PyrosROS' referenced before assignment
[rostful-1] process has died [pid 11274, exit code 1, cmd /home/dkurzaj/catkin_ws/src/rostful/scripts/devserver -p 8080 -s flask ~connections_list:=/rocon/connection_cache/list ~connections_diff:=/rocon/connection_cache/diff __name:=rostful __log:=/home/dkurzaj/.ros/log/92e87824-3c5a-11e6-aa36-64006a5f3285/rostful-1.log].
log file: /home/dkurzaj/.ros/log/92e87824-3c5a-11e6-aa36-64006a5f3285/rostful-1*.log
asmodehn commented 8 years ago

Hello,

Thank for taking the time to try it and report this issue. From your environment it looks like you are mixing catkin workspaces with python venv, which is one of the target for rostful. However this is tricky to get right for all usecases, so thanks again for the details you put here.

First, it's likely that the doc you had a look at is outdated. Feel free to make a PR, or otherwise point me in the right direction and I ll try to find some time to fix it.

python -m rostful flask

Is an outdated command.

If you check https://github.com/asmodehn/rostful/blob/indigo-devel/rostful/__main__.py you ll see the available python commands and arguments.

So this should work out of the box with indigo-devel version

python -m rostful 

About

roslaunch rostful rostful.launch

It looks like pyros is failing to import some modules :

WARNING:root:Error: Could not import PyrosROS from .rosinterface.pyros_ros cannot import name core

We would need to dig deep to find where that "core" module is imported. but that is likely caused by an unexpected python setup.

Running python -m site would give you an idea of the different path where python is looking for modules, and when jumping between a catkin workspace and a virtualenv, it is likely that we find some issues.

In your commands I don't see anywhere source devel/setup.bash which is the usual catkin way to get the PYTHONPATH modified to include ros library (after you build your workspace with catkin_make). it might be just that or it might be something more complicated...

I haven't investigated your usecase fully yet (but I am very interested in doing it - just didnt get the time, since I use primarily the catkin workflow), so if you want something to run quickly I would advise, for now, to stick to the catkin+rosdep way of doing things.

And if you have some motivation to help and dive into how to use python and virtualenvs with catkin workspaces, I can point you to https://github.com/asmodehn/catkin_pip and more specifically to https://github.com/asmodehn/pyros/tree/config_refactor where the latest development is going on.

asmodehn commented 8 years ago

Ah Another useful piece of information... This :

WARNING:root: => Emulating ROS setup now for distro indigo and workspaces ()
WARNING:root:Appending path /opt/ros/indigo/stacks to ROS_PACKAGE_PATH
WARNING:root:Appending path /opt/ros/indigo/share to ROS_PACKAGE_PATH
WARNING:root:Appending path /opt/ros/indigo/bin to PATH
WARNING:root:Appending path /opt/ros/indigo/lib to LD_LIBRARY_PATH
WARNING:root:Appending path /opt/ros/indigo/lib/pkgconfig to PKG_CONFIG_PATH
WARNING:root:Prepending path /opt/ros/indigo/lib/python2.7/dist-packages to PYTHONPATH
WARNING:root: => ROS setup emulation done.

is created by https://github.com/asmodehn/pyros-setup.

This is the package in charge of loading the ROS environment, when someone uses python directly, without sourcing the ROS environment as per the normal catkin workflow. I understand this is your case...

There are two versions currently out there of this package :

If you go for using the python workflow, you want to make sure you have the latest pyros_setup from pypi installed, and you want to make sure the config file points to your ros workspaces (built catkin workspace, including any underlays). Config file should be created if it doesn't exist...

If you go for catkin workflow, the pyros-setup is not needed and should not even be imported (since 0.1.0)

I know all this is tricky, so feel free to ask any questions. It will also help get these python packages working properly with ROS.

Cheers !

asmodehn commented 8 years ago

Just to let you know I recently made a detailed tutorial to use rostful the catkin way : https://github.com/asmodehn/rostful/blob/indigo-devel/doc/tutorial.rst

Hopefully this should help you get it running.