Use third party python library
How to include third party python libraries in the ROS? I wanted to use this library https://github.com/boppreh/keyboard Please let me know the step by step procedure to include any python library in ROS and use it. Here is the code which runs fine without rospy in a python environment but does not works in ROS:
import keyboard
import rospy
from ros_basics.msg import Keyboard
def main():
rospy.init_node('KeyboardData',anonymous=True)
rate = rospy.Rate(1)
while not rospy.is_shutdown():
data = Movement()
publisher = rospy.Publisher('data',Keyboard,queue_size = 25)
up = keyboard.is_pressed('up')
down =keyboard.is_pressed('down')
right = keyboard.is_pressed('right')
left = keyboard.is_pressed('left')
if(up):
print("Up key pressed")
data.up = True
publisher.publish(data)
rate.sleep()
if __name__ == "__main__":
try:
main()
except rospy.ROSInterruptException:
pass
What do you mean by that? It contains a lot of ROS specific stuff. How does this work without ROS then?
Also, are there any error messages?
Pleas tell us how you installed the library, as there are several options shown in the README... Also, what have you tried so far. What is working and what is not...
I meant to say that it runs fine without rospy and it's stuffs in a python environment but does not work in ROS. I want to install python library or basically install a third party Non -ROS library(Since i am using JETSON TX2i, which has a python library for it's GPIO) from github and use it in ROS. I installed the library using pip install keyboard since it is a non-ROS library. I wanted to know the way to use/install non-ROS libraries of python available in github with ROS. The error given when using ROS along with the library is import error and unexpected token "(" which by the way works fine when i remove all keyboard code.
Can you please edit your question by posting the exact error output via copy and paste? Then we wouldn't have to dig around in the dark that much.
So, installation via
pip
is fine and usually works fine (assuming, you have installed the Python2.7 version, and not the Python3 one).So, it might be an issue with the wrong python version.
Can you try to open an interactive python2.7 console and see if the import error is there as well?
Last but not least, from the docs of the library:
I'm not sure if this is a dealbreaker for you, but this seems a bit overkill and I wouldn't run a script that requires root privileges simply to read from the keyboard. This is a python ...(more)