rclpy import in application fails
Hi,
i trying to import the rclpy libary in an application written in python.
if i use #import rclpy
i alway get an error message like this
ImportError: DLL load failed: ...
The C extension 'C:\ros2\install\Lib\site-packages\rclpy_rclpy.pyd' failed to be imported while being present on the system. Please refer to 'https://github.com/ros2/ros2/wiki/Rclpy-Import-error-hint' for possible solutions
But when i run the demo_nodes_py everything seems to work fine
I dont want to build the python package with ament or colcon i just want to use the rclpy API is this possible ?
edit: it works with this parent script
def main():
# extend the path first by prepending ros2 path settings
path = os.environ.get('PATH').split(os.pathsep)
path = [os.path.join(ROS_INSTALL_DIR, 'Scripts'), os.path.join(ROS_INSTALL_DIR, 'bin')] + path
os.environ['PATH'] = os.pathsep.join(path)
# extend the pythonpath with the ros2 site packages
pythonpath = os.environ.get('PYTHONPATH').split(os.pathsep)
pythonpath = ['C:\\ros2\\install\\Lib\\site-packages\\'] + pythonpath
os.environ['PYTHONPATH'] = os.pathsep.join(pythonpath)
# spawn a python process with extended environment
subprocess.check_call([sys.executable, SCRIPT], env=dict(os.environ))
How are you getting ROS (from a .zip or did you build it yourself)? It looks like you're maybe using a debug build (given the
.pyd
) are you usingpython_d
?i installed ROS2(bouncy) from source and using a normal python3.7 release on Win10
Did you source the
setup.bat
file? What is yourPYTHONPATH
andPATH
look like?BTW, I was wrong about
pyd
, that's just a dll not necessarily a debug build.so i can get it to work with the local_setup.bat but when i try to manually extend the PYTHONPATH and PATH to use the rclpy API it always fails
You should always be using the setup script because it sets other things like environment variables for middlewares and standard things like
ROS_DOMAIN_ID
, but without seeing the difference in your Python path and the one the setup script sets I can't really help.