When i type import pygame, i get an error that reads:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
File "C:\Python27\lib\site-packages\pygame\__init__.py", line 95, in <module>
from pygame.base import *
ImportError: DLL load failed: The specified module could not be found.
>>>
Does anybody know what this means?
It means that you need to look at pygame\base.pyd in Dependency Walker and see which DLL it can't find.
I made this mistake too. The problem is that you are using the Idle Shell to attempt to build a Python program. Here is how I get out of the shell:
Save the Idle Shell as a .py in a location of your choice
Afterward, find the .py you created.
Left click, then Right click to display the context submenu (the menu with copy/paste)
Select "Edit with Idle"
This will open the .py file in the Editor Window. Delete all extra content to create a blank screen
Now you can import your modules and begin programming:
import os, sys
import pygame
from pygame.locals import *
[...]
This will give you the head start to work with pygame.
This question at Game Developement (another Stack Exchange Site) should answer your question:
Installing the right version of PyGame
This user can't make Python to know that PyGame is there so he asks that question. His question should be similar to yours, making it convinient for you. I hope this helps you!
In the command prompt, write pip install pygame if you have a Windows PC, or pip3 install pygame if you have Linux or MacOS.
Related
I have recently changed my text editor from IDLE to Atom but when I started to run my program that i have ran in the past eg(music player using pygame) it didn't work and came up with this error message:
Traceback (most recent call last):
File "/Users/jacquelinethompson/Desktop/Untitled.py", line 1, in <module>
import pygame
ImportError: No module named pygame
[Finished in 0.088s]
I checked the import to see if it worked in IDLE and it works fine there. Can anyone explain why and how to fix it.
I am on the MacOS and am using python3.6
I was making a program using pywhatkit to send WhatsApp messages. However, when trying to import pywhatkit, the following exception is raised:
(Sorry, I was not able to copy the error message.)
Can anyone tell me why this is happening?
One of the dependencies of pywhatkit is the pyautogui module (see here for what pyautogui is). REPL.it runs on Linux, a Unix-like OS; on Unix, pyautogui requires Xlib (hence, Xlib.error.XauthError). On importing pywhatkit, Xlib attempted to open the .Xauthority file, but failed to do so, in this case because the file does not exist. I believe this behavior has to do with REPL.it itself, i.e., there's nothing you can do about it.
For background on what the .Xauthority file is, refer to this AskUbuntu question.
Whenever I run my code in the IDLE's shell, it always comes out with this error:
Traceback (most recent call last):
File "C:\Users\dELL\Desktop\MyProject\ReactionTimeProgram.py", line 2, in <module>
import pygame
ImportError: No module named pygame
Is it telling me I haven't installed Pygame, because I have.
How can I fix this error?
Best Regards
RMR :)
Are you running the proper version of python? When I run pygame with python2 instead of python3, that's what happens for me.
I am running Windows 7 and have Python 3.3 64 bit installed. I seem to have a problem importing the tkinter module, I can import it fine through the python IDLE and it will work, but when I save the .py file and double click it, a cmd window will open and say:
Traceback (most recent call last):
File "C:Users\username\Desktop\g.py", line 3, in <module>
from tkinter import *
ImportError: No module named tkinter
I have tried the following:
I have tried import tkinter, from tkinter import *, and import tkinter as tk and they don't seem to work when the .py file is opened directly (double clicked).
I also double checked the path variable and it was set correctly.
I uninstalled python and reinstalled it.
I checked to see if tkinter is in the folder C:\Python33\Lib\, and it is.
I do have a mainloop() in my program.
In my program, tkinter is all lowercase.
I tried a lot of solutions online from other posts, and they didn't work for me.
The top of my code is:
import sys
from tkinter import *
I don't know what I am missing, any suggestions?
I'm going to make this an answer then for anybody in the future.
The problem is that Windows is currently set to run all .py files with a different executable (probably a Python 2.x one) To fix the problem, follow these steps:
Right-click a .py file.
In the menu that pops up, go to Open with.
In the submenu that pops up, click on Choose default program...
A window will then appear. In this window, click on the Browse... button.
Then, go find the Python execuatble. It should be at C:\Python33\python3.3.exe. (There might be multiple pythonX.exe files. If one doesn't work, try another.)
Once you select it, click Open.
If done correctly, this procedure will manually reset the default executable for .py files to be the Python 3.x one. Meaning, your script should run fine now.
This is actually a simple solution.
You have:
from tkinter import *
You need:
from Tkinter import *
Capitalization is very specific!!!
1) I am getting error on the python script if i run it through sublimetext. How do i map my existing python to sublime text rather than using the one comes with sublimetext ?
import Tkinter as tk
import tkinter
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named tkinter
i think the tool use its own python.
2) is there a short key like (the common F5) to run the script on sublimetext ?
Please suggest.
Thank you
The Python builder in Sublime Text runs the active Python file with the Python executable found in your PATH. You can start it with Tools -> Build (Ctrl + B).