I created a python file inside <package_name> folder then using ros2 run …
It works very well
But if I try to run a python file from another folder outside <package_name> folder, it will not work.
How can I run the python file outside <package_name> folder
ros2 run only works for Python executable created within the ROS system and specifications, and properly specified in setup.py. You cannot use it for running any random Python executable.
You can, however, run a Python file the traditional way:
python /path/to/your/python_file.py
Please note that this might not work if your Python code is supposed to access ROS resources. If that is the case, they you must create it the “ROS way.”
Btw, why do you want to have the Python file outside the package?
You create a Python file inside the folder with the same name as the package name.
I read the documents, it works well.
In ROS1, we create a folder named script (not inside the folder same name as the package name) and then create a Python file. I still use the command “ros run”. But ros2 run does not work like that
So my question is if there is any way I can do ros2 run with the python file inside script folder that not inside the “package name” folder?