This question already has answers here:
random module error when run as .py
(3 answers)
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 4 years ago.
Code:
import turtle
import random
turtle.penup()
for i in range(20):
x=random.randint(-200,200)
y=random.randint(-200,200)
turtle.setposition(x,y)
turtle.dot()
turtle.done()
Error:
F:\Python>random.py
Traceback (most recent call last):
File "F:\Python\random.py", line 2, in <module>
import random
File "F:\Python\random.py", line 5, in <module>
x=random.randint(-200,200)
AttributeError: module 'random' has no attribute 'randint'
Rename your file.
Make sure that no files are named random.py.
Related
This question already has answers here:
ImportError: No module named 'resource_rc'
(5 answers)
Closed 7 months ago.
I converted QT .ui file into .py file and when I run it I get this error?
Traceback (most recent call last):
File ~\Desktop\Project\main2.py:14 in <module>
from ui3 import Ui_Form
File ~\Desktop\Project\ui3.py:39 in <module>
import rec_rc
ModuleNotFoundError: No module named 'rec_rc'
The following solution if provided by eyllanesc in this question, and it seems to be the same error as yours.
You should have a file called rec.qrc, this must be converted to
.py, this or you can do it by executing:
pyrcc5 rec.qrc -o rec_rc.py
This question already has an answer here:
Python ImportError: cannot import name itemgetter
(1 answer)
Closed 2 years ago.
When I tried in Mac os with python 3.8.3
this code:
from turtle import *
shape("turtle")
I get this error:
Traceback (most recent call last):
File "C:\Users\jeeva\Desktop\Tanmay_new\python\pi\Draw_pi\draw_pi.pyw", line 2, in <module>
shape("turtle")
NameError: name 'shape' is not defined
It looks like python doesn't reconize shape.
Please help me.
See if you have a file named turtle.py other than the module. Rename it and try again
This question already has answers here:
tkinter woes when porting 2.x code to 3.x, 'tkinter' module attribute doesn't exist
(1 answer)
Substitute for tkinter.dooneevent
(1 answer)
Closed 4 years ago.
I'm using Python3, I have a program written in Python2, I converted to Python3 using 2to3 command.
After running the code an error had occurred:
AttributeError: module 'tkinter' has no attribute 'tkinter'
Traceback (most recent call last):
File "pacman.py", line 679, in <module>
args = readCommand( sys.argv[1:] ) # Get game components based on input
File "pacman.py", line 567, in readCommand
import graphicsDisplay
File "graphicsDisplay.py", line 15, in <module>
from graphicsUtils import *
File "graphicsUtils.py", line 294, in <module>
def keys_pressed(d_o_e=tkinter.tkinter.dooneevent,
AttributeError: module 'tkinter' has no attribute 'tkinter'
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 2 years ago.
As a beginner in Python, I really don't know what I'm doing wrong here?
I would like to work with pyautogui:
>>> import pyautogui
>>> pyautogui.PAUSE = 1
>>> pyautogui.FAILSAFE = True
>>> pyautogui.size()
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
pyautogui.size()
AttributeError: module 'pyautogui' has no attribute 'size'
Don't know why it doesn't show my resolution? And in general, pyautogui doesn't work with commands like:
>>> pyautogui.moveTo(100, 100, duration=0.25)
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
pyautogui.moveTo(100, 100, duration=0.25)
AttributeError: module 'pyautogui' has no attribute 'moveTo'
>>>
I'm sure I installed pip.
Your own script which is named "pyautogui.py" is interfering with the module you installed — so rename it something else.
This question already has answers here:
Importing installed package from script with the same name raises "AttributeError: module has no attribute" or an ImportError or NameError
(2 answers)
Closed 5 years ago.
When I import urllib.request in python 3, I get the following error:
Traceback (most recent call last):
File "urllibExample.py", line 1, in <module>
import urllib.request
File "/home/andrew/Python/urllib.py", line 1, in <module>
import urllib.request, urllib.parse, urllib.error
ModuleNotFoundError: No module named 'urllib.request'; 'urllib' is not
a package
I'm not sure why I'm getting this error message since urllib.request is in the standard library. Does anyone know how to fix this?
You appear to have a file of your own named urllib.py. The import is being attempted from this file instead of the system installed one.
Rename your file.