(AttributeError) installation problem with keyboard - python

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?

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

I can't run Custom-Widgets for PyQt5, how can I solve it?

I tried to simplify my code with the tool Custom-Widgets, I want to custom a animated menu, after the installation of Custom-Widgets from https://github.com/KhamisiKibet/QT-PyQt-PySide-Custom-Widgets
I try to prove it with the demo:
from Custom_Widgets.ProgressIndicator import test
test.main()
but It doesn't find the package of this.
I had this output:
Traceback (most recent call last):
File "c:\Users\user\Desktop\try\provePyQT.py", line 1, in <module>
import Custom_Widgets
ModuleNotFoundError: No module named 'Custom_Widgets'
What can I do with this error?

Python Turtle Module not Working on Windows 10

I am new in programming. I have an issue. my python code is:
import turtle
turtle.forward(100)
turtle.exitonclick()
I already install turtle on my desktop. But VsCode Error message is:
Traceback (most recent call last): File "d:/Code
Practice/Python/turtle.py", line 1, in
import turtle File "d:\Code Practice\Python\turtle.py", line 3, in
turtle.forward(100) AttributeError: partially initialized module 'turtle' has no attribute 'forward' (most likely due to a circular
import)
The file you are working on has the same name as the turtle module. So, your file overwrites the module and now you are importing your own file. And that file has no forward function, so it isn't working.
Try renaming your file to something else and give it a try.
You have named you file turtle.py because of which python imports that file as the module and also runs the same file while running which creates a loop and gives that error Solution: Name your file something else. For example- turtle_.py or whatever else you want except for the modules name itself as that is reserved for the python interpreter.✌

Module is in correct folder, but still says that it cannot be found

I have pygame and numpy in the same folder. I can import pygame, but I can only import numpy in the terminal, not even in the IDLE. If I try to import numpy anywhere else, I get this message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
I can also still import pygame into the terminal. Also, python in the terminal is version 3.7.5, but in the IDLE it's 3.6.6. Not sure if that's related.
All of my modules are in the default path folder.

python Name 'package' is not defined error

After installing the pyautogui package with pip, I tried using it in the IDLE shell by typing pyautogui.
However I get the following error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
pyautogui
NameError: name 'pyautogui' is not defined
I have scoured the web but have not been able to identify why IDLE will not recognise that pyautogui is installed.
Please let me know if you need more information to answer.
Have you tried importing the package first?
Try:
import pyautogui

Jedi-vim doesn't work

I have a issue with VIM. I'm trying to install jedi-vim according to https://github.com/davidhalter/jedi-vim
but when I open vim, it report such error:
initialize.py" 25L, 831C'import site' failed; use -v for traceback
Error detected while processing /home/.../.vim/autoload/jedi.vim:
line 285
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/.../.vim/initialize.py", line 10, in <module>
import os
ImportError: No module named os
And when I use Ctrl+Space in vim, it results in
Error detected while processing function jedi#completions:
line 1:
Traceback (most recent call last):
Press ENTER or type command to continue
In fact, I don't get any error when importing os from the command line..
import os
os,
module 'os' from '/usr/local/install/python-2.7.5/lib/python2.7/os.pyc'
Anybody know how to solve this error?Thank You.
Pretty sure that there's something wrong with your VIM. You're probably using vim on mac and there's something wrong with the sys.path.
You should be able to use :python import os in VIM. If that doesn't work, Jedi certainly won't.

Categories

Resources