You need to figure out a way to ensure you are running Python 2.7 and try again.
Most likely you aren't using python 2.7 like you think you are.
Check python from command line by typing
Then to make sure login to Python command line by typing
python and see what version it spits out in the welcome message and type
exit() to exit.
Once you confirm you are running 2.7x then install onionpy via pip:
pip install onionpy. Also make sure you have Tor running, or onionpy will malfunction.
Do a test (should return summary of current relays)
from onion_py.manager import Manager
from onion_py.caching import OnionSimpleCache
manager = Manager(OnionSimpleCache())
s = manager.query('summary', limit=4)