The second snippet is not supposed to work outside REAPER... We've all tried it I guess! The module "reaper_python.py" is dynamically built and, simply put, can only work inside REAPER.
About your first snippet, have you followed the
installation instructions and especially the
Enable reapy distant API part?