Getkey issue / error initializing

Hello !
here my error message when i run my module :
“Error initializing standard platform: Cannot use unix platform on non-file-like stream”

Thanks a lot in advance.

Mac 10.14
Python 3.12
getkey 1.60 installed with pip

my code on IDLE, I’m on test step :
from math import *
import playsound
from getkey import getkey, keys

def play () :
lettre = ‘in’
fichier = ‘.mp3’
while lettre != ‘out’ :
lettre = str(input(“Tapez une lettre au clavier : \n”))
fichier = lettre + ‘.mp3’
print(fichier)
playsound.playsound(fichier)

def fct () :
key = getkey()
if key == ‘b’:
print(key)

Handle the UP key

    elif key == 'c':
            print(key)

Handle the DOWN key

    elif key == 'a':
            print(key)

Handle the a key

    elif key == 'Y':
            print(key)

Handle shift-y

    else:

Handle other text characters

      buffer += key
      print(buffer)

Please use pre-formatted text feature to show you code.
You can edit you post to fix use. You the triple back-quotes like this:

```
def myfunc():
    print('Hello')
```

Hello !
here my error message when i run my module :
“Error initializing standard platform: Cannot use unix platform on non-file-like stream”

Thanks a lot in advance.

Mac 10.14
Python 3.12
getkey 1.60 installed with pip

my code on IDLE, I’m on test step :

from math import * 
import playsound
from getkey import getkey, keys


def melo1 () :
        lettre = 'in'
        fichier = '.mp3'
        while lettre != 'out' :
                lettre = str(input("Tapez une lettre au clavier : \n"))
                # lettre = getkey()
                if lettre not in 'abcdefghijklmnopqrstuvwxyz0123456789' :
                        if lettre != 'out' :  
                                lettre = 'inconnu'
                fichier = lettre + '.mp3'
                playsound.playsound(fichier)


def fct () :
        key = getkey()
        if key == 'b':
           print(key)             
        elif key == 'c':
                print(key)
        elif key == 'a':
                print(key)
        elif key == 'Y':
                print(key)
        else:
          buffer += key
          print(buffer)

Please show a complete error message by copying and pasting, starting from the line that says Traceback (most recent call last): until the end, and formatting it the same way as the code. (Feel free to redact file/path names if they are sensitive.)

When I do F5 (run module) I see this :

Error initializing standard platform: Cannot use unix platform on non-file-like stream

When I call function, I see this :

fct()
Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    fct()
  File "/Users/lolo/Documents/Laurent/Python codes/test1.py", line 20, in fct
    key = getkey()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/getkey/platforms.py", line 39, in getkey
    for c in self.getchars(blocking):
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/getkey/platforms.py", line 66, in getchars
    char = self.getchar(blocking)
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/getkey/platforms.py", line 218, in getchar
    raise RuntimeError('Cannot getkey on invalid platform!')
RuntimeError: Cannot getkey on invalid platform!

The latest version I’m seeing of the getkey package on PyPI is 0.6.4 from 2016, nearly 8 years ago, and only declares support up to Python 3.5. It may simply not support modern Python. Alternatively, if you are using some fork (I couldn’t easily find one on PyPI with that version), there may be a bug in it not supporting your specific OS/version.

1 Like

Thanks for informations about versions.
The main purpose in fact is to find a function that can send me the character that I type on keyboard. str(input()) can do it but I need to type ‘enter’ and I don’t want.
Do you know another function equivalent to getkey ?

The usual recommendation for this is probably pynput. It also handles mouse input.

You may be able to find some other suggestions here:

Thanks a lot. i 'll work on this way