Just add your /opt/ros/<ros_name>/setup.bash to the end of /etc/profile.
/opt/ros/<ros_name>/setup.bash
/etc/profile
This problem is caused by that Jetbrains Pycharm don't inherit the symbols of ros2 in the setup.bash.
setup.bash