I have a particular script that uses the “keyboard” library for python. I have had a few users report issues around this particular script. For some, it returns an error saying "Unsupported platform ‘cli’.
I tracked down this error in the init file for the keyboard library and it comes in here:
import platform as _platform
if _platform.system() == 'Windows':
from. import _winkeyboard as _os_keyboard
elif _platform.system() == 'Linux':
from. import _nixkeyboard as _os_keyboard
elif _platform.system() == 'Darwin':
from. import _darwinkeyboard as _os_keyboard
else:
raise OSError("Unsupported platform '{}'".format(_platform.system()))
I would expect any computer in our company to return “Windows”, but some are returning “cli”. Is this in any way related to pyRevit CLI?
I have had some success with wiping pyRevit off their machine and doing a fresh install, but I’m just curious if it actually has anything to do with pyRevit at all.
Hi @DennisGoff,
Does it occur also with a minimal script like tha following?
import platform
print(platform.system())
If it does, try to disable your extensions and create a new one with only this script (or move out the other folders from your extension temporarily), just to rule out conflicts in the loaded libraries.
Yes, when I had a user experience this, this is the first thing I did once I traced down where the error was coming from. The simple script you show there returns the same “cli” answer
I found a thread on an unrelated github project that reported the same issue, so perhaps it’s not related to pyRevit at all. I had just thought that maybe “cli” had to do with pyRevit CLI…
They closed the issue stating that they can “assume cli means windows”. Not the most encouraging answer, but I went into the code for the keyboard module and added this and it works now:
if _platform.system() == 'Windows' or _platform.system() == "cli":
from. import _winkeyboard as _os_keyboard
Im glad you solved it!
Just a tip, you can use if platform.system() in ("Windows", "cli"):
to get the same result.
By the way, what do you use the keyboard library for?
I see that the last commit on their repo is from 2 years ago, and there are 378 open issues, so I would find another solution if I were you.
I have an updater listening for changes to view templates. I use keyboard to simulate pressing “escape” to get out of the menu without applying the changes. Do you know of any other good python libraries for simulating key presses?