Home > other >  (AttributeError) installation problem with keyboard
(AttributeError) installation problem with keyboard

Time:04-20

I am having a issue when I try to use the keyboard module. My code is:

import keyboard
keyboard.write('Hello.', 0.3)

And the error was:

C:\Users\user\AppData\Local\Programs\Python\Python310\python.exe "C:/Users/user/Desktop/simple brain/keyboard.py"
Traceback (most recent call last):
  File "C:\Users\user\Desktop\simple brain\keyboard.py", line 1, in <module>
    import keyboard
  File "C:\Users\user\Desktop\simple brain\keyboard.py", line 2, in <module>
    keyboard.write('Hello.', 0.3)
AttributeError: partially initialized module 'keyboard' has no attribute 'write' (most likely due to a circular import)

Process finished with exit code 1

I used pip install keyboard in pycharm terminal. How do I fix the installation of or properly install keyboard?

CodePudding user response:

The name of your file is "keyboard.py". When you do import keyboard, python is trying to import your current file which is causing a circular import. Rename your file to something else.

  • Related