In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the ROS system to compile the python package into an executable file related knowledge, the content is detailed and easy to understand, simple and fast operation, has a certain reference value, I believe that after reading this ROS system to compile the python package into an executable file method article will have a harvest, let's take a look at it.
1. Download must file git clone https://gitee.com/alen2020/ros_python_install_mode_files## to take the cmake directory under this directory and setup.py,install.sh to your own node directory cp-r cmake setup.py car_mqtt_api/
If dynamic parameters are used, you also need to copy install.sh and make the following modifications (if dynamic parameters are needed, please ignore the following)
Cp install.sh car_mqtt_api/## needs to modify the package_name under install.sh to the current package name package_name=package_path= `rospack find ${package_name} `if [$#-eq 1] Then package_path=$1fi# note that the .py file is placed in the src directory by default. If you put it under scripts, it needs to be changed to scripts # my default ROS workspace prefix directory is / root/ROS/catkin_ws/, if not, please modify mkdir $package_path/src/$package_name/cfgcp / root/ROS/catkin_ws/devel/lib/python2.7/dist-packages/$package_name/cfg/* $package_path/src/$package_name/cfg2. Transform the directory structure # # the original structure, .py files should be placed in the scripts folder ls
The main function remains in the current directory, and the called file is placed in a subdirectory, which is the same as the name of this package
3. Create a CMakelist rule (with reference relationship)
1) modify the CMakelist under the current package
Add the following content, in which add_subdirectory adjusts according to the directory where its python files are stored
Set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR} / cmake) # include CMake module for Cythoninclude (UseCython) add_custom_target (ReplicatePythonSourceTree ALL ${CMAKE_COMMAND}-P ${CMAKE_CURRENT_SOURCE_DIR} / cmake/ReplicatePythonSourceTree.cmake ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory (src) # # if dynamic parameters are used Need to add the following statement add_custom_target (install.sh ALL) add_custom_command (TARGET install.shPOST_BUILDCOMMAND / bin/sh ${PROJECT_SOURCE_DIR} / install.sh ${PROJECT_SOURCE_DIR}))
2) add CMakeLists.txt under the scripts directory
Every referenced file should be written in, and the file name of the main function should be written at the end.
# # add a subdirectory add_subdirectory (mypackage) cython_add_standalone_executable (1 MAIN_MODULE 1.py mypackage/2.py 1.py) install (TARGETS 1 RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
3) add CMakeLists.txt under a subdirectory of the scripts directory
All referenced files need to add rules
Cython_add_module (2 2.py) set_target_properties (2 PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX} / ${CATKIN_PACKAGE_PYTHON_DESTINATION}) install (TARGETS 2 LIBRARY DESTINATION ${CATKIN_PACKAGE_PYTHON_DESTINATION}) omit the following. 4. Non-reference relationship (single file)
Write twice
Cython_add_standalone_executable (car_mqtt_api_main MAIN_MODULE car_mqtt_api_main.py car_mqtt_api_main.py) install (TARGETS car_mqtt_api_main RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}) 5. How to reference a package
You need to add a subdirectory prefix after changing the rule
Dynamic parameter adjustment of from mypackage.2 import function6.cfg after modification of original from mypackage import 2
As mentioned earlier, the subdirectory should have the same name as this node, because the compiled subdirectory will not be named by the name of the subdirectory, but by the node name. The executable files generated by the compilation will be placed under the lib/python2.7/dist-packages of devel or install, while running in source mode will read the cfg files under the subdirectory.
For example, the executable program that dynamically adjusts parameters after car_mqtt_api compilation is placed in the following directory
Devel/lib/python2.7/dist-packages/mypackage/cfg
At this point, you need to copy the files in this directory to a subdirectory.
Mkdir-p mypackage/scritps/cfgcp * / devel/lib/python2.7/dist-packages/mypackage/cfg scripts/mypackage/cfg7. Common bug
Module not found: place the _ _ init__.py file in the install/lib/python2.7/dist-packages/car_control directory
This is the end of the article on "the method of compiling python packages into executable files in the ROS system". Thank you for reading! I believe you all have some knowledge about "the method of compiling python packages into executable files in ROS system". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.