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.
Related
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:
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.
This question already has answers here:
How do I find the location of Python module sources?
(20 answers)
Closed 5 years ago.
I apparently have multiple versions of a module installed and I am trying to figure out where the files are because only one of them is from package management and I want to delete the other.
Is there a simple way to ask Python where it found a module after importing it?
if the module isn't built-in, you can do this:
import your_module
print(your_module.__file__)
test:
>>> import os
>>> print(os.__file__)
L:\Python34\lib\os.py
if module is built-in, you get an error:
>>> import sys
>>> print(sys.__file__)
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
>>>
(check if module has the __file__ attribute using hasattr is also an option to avoid errors; if hasattr(module_name, '__file__'):)
also: by directly printing the module:
>>> print(os)
<module 'os' from 'L:\\Python34\\lib\\os.py'>
You can use __file__ after importing the module:
>>> import os
>>> os.__file__
'/usr/lib/python2.7/os.pyc'
I'm new to Python, and I'm trying to get started with Pygame.
When I run this code:
import pygame
pygame.init()
I get this error:
Traceback (most recent call last):
File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 6, in <module>
pygame.init()
AttributeError: 'module' object has no attribute 'init'
But when I try to see if I accidentally imported another file:
import pygame
import inspect
# Initialize the game engine
print(inspect.getfile(pygame))
pygame.init()
I get this weird error:
Traceback (most recent call last):
File "C:\Users\Jason\PycharmProjects\Game\myapp.py", line 5, in <module>
print(inspect.getfile(pygame))
File "C:\Python34\lib\inspect.py", line 518, in getfile
raise TypeError('{!r} is a built-in module'.format(object))
TypeError: <module 'pygame' (namespace)> is a built-in module
How can I import the right Pygame?
I'm using 3.4 on Windows 7 and Pygame 1.9.2a0 (for 3.2) in C:/Python34.
Thank you
It all has to with the version. That simple.
The original answer was here: https://stackoverflow.com/a/23484831/2486953
I had to download the 64 bit version from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Thanks #BrenBarn for your help!
This question already has answers here:
ImportError: No module named _ssl
(9 answers)
Closed 9 years ago.
I'm getting an error because the ssl module isn't available
If I run help('modules') from the python interpreter it is listed there
When I try to import it from the interpreter, I get
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
Ensure that you have openssl package installed.