So I just came up with a problem that i don't understand.
I have two python files one is for the separate game menu, and second for the game.
The menu is written with tkinter and the problem comes when I click( in my menu ) 'Start game' button. It destroys menu, but does not open another file - game. Here's the code from menu where the problem occurs.
root.destroy()
os.system('main.py')
That's what console says:
Traceback (most recent call last):
File "main.py", line 8, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
Initial code from the second file (game file)
from backdoor import *
import pygame
from Config import *
pygame.init()
When I start only the game file it works as it should - there's no Errors, that's why i have no idea why this problem occurs. I'm new to coding so would appreciate any help and explanations.
To import pygame you must have it installed:
pip3 install pygame
If you have it already installed try to reinstall
pip3 uninstall pygame
pip3 install pygame
Found the solution, so the problem was my sillnes and a lack of knowledge. I was using Anaconda environment and I've installed pygame with navigator cmd, so i thought that it's installed. I've reinstalled Python and added pip path in cmd with setx PATH "%PATH%;path", then I could actually install pygame and now everything works properly. Thanks for help!
Related
I am using a windows system and I have no idea why after I use the command "pip3 install pyautogui" it installs successfully however when I click the play button in VS code it gives me an error in the terminal -
ERROR
import pyautogui
ModuleNotFoundError: No module named 'pyautogui'
I am a pure beginner to Python so I have no idea what might be causing this issue. My code is below:
CODE
import pyautogui
screenWidth, screenHeight = pyautogui.size()
print(screenWidth)
print(screenHeight)
Any idea what I can do to solve this? I have checked similar questions but the answers were targeted more towards Linux users.
sometimes pip can have problems with certain libraries.
to get around this, you should download the .whl or tar.gz file and install it directly from there.
this is the .tar.gz file for pyautogui: https://files.pythonhosted.org/packages/f0/76/7a0ec1013bc3559b7438f6773cba05ffaec600b8989be2d621a144e39b50/PyAutoGUI-0.9.53.tar.gz
download it and put it in your project directory.
then, just pip install {THE FILE NAME}.
for me that fixed it.
At the top of my python code, I put import pygame as usual, and have installed the module on my computer. So why do i get this when running my code? I have already tried deleting pygame and reinstalling it and it has not worked. The files are on my computer. Can anyone help me?
Traceback (most recent call last):
File "C:\Users\<myuser>\Documents\RPG\main.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
I think you might not have added the python path when you installed python. If you're using windows, search for Edit the system environment variables. Click on Environment variables, in the system variables section, double click on path -- and add the path of your python software.
ex: C:\Program Files\Python310\Scripts\ & C:\Program Files\Python310*
I am trying to use a Tkinter module as suggested on the following website: https://likegeeks.com/python-gui-examples-tkinter-tutorial/. My expectation was to create my first GUI application as shown on the website by creating window = Tk(). Instead, I am getting the following error:
Traceback (most recent call last):
File "C:/Users/Daniel/Desktop/Python Projects/untitled-2.py", line 3, in <module>
pass
File "C:\Users\Daniel\AppData\Local\Programs\Python\Python37\Lib\tkinter\__init__.py", line 2018, in __init__
baseName = os.path.basename(sys.argv[0])
builtins.IndexError: list index out of range
I do not know what is causing this error but it appears chronic. My code is the same as the following:
from tkinter import *
window = Tk()
Please advise me of what I need to do in order to address this issue.
Thank you.
Well I think you should try the following!
1st Method: Try reinstalling OS and Tkinter module
Open CMD
Type these commands one after the other:
py -m pip uninstall os
py -m pip uninstall tkinter
Reinstall these modules using the following commands:
py -m pip install os
py -m pip install tkinter
Now try running your program again.
2nd Method: Reinstall Python
Open Contrl Pannel<Program and Features then find the Python Application in the list. Then uninstall it.
Download the setup of Python from: https://www.python.org/downloads/
Find the version you want and then download the setup. Reinstall Python just as you did before.
Now try again with the program. It is most likely to work.
Thank You! :)
Basically, i'm trying to use the turtle module at home as I have been using it in school and it's quite fun to use. However, when I try to import it and run the code, it says that there is an error in line 1 of the code and says that no module named pygame was found. I didn't write pygame, I specifically wrote
from turtle import *
which at school works perfectly fine. Both my computer and the school computers use Python 3.6 but the turtle module will just not work at home. Any ideas why this might be happening? If it helps, I've tried to install pygame in the past but it wouldn't work so I stopped trying to install it, and just now I tried deleting and uninstalling pygame but it still shows up with the error. Thanks for taking your time to read my question.
The error that comes up is as follows:
Traceback (most recent call last):
File "C:/Users/homeuser/AppData/Local/Programs/Python/Python36-32/jsjs.py", line 1, in <module>
from turtle import *
File "C:/Users/homeuser/AppData/Local/Programs/Python/Python36-32\turtle.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
>>>
Also, pip install pygame comes up with an error saying invalid syntax
First, you need to download the version of pygame suitable for your version of python. Here's a link to their download page: https://pypi.python.org/pypi/Pygame/1.9.3
Next, open the command prompt. This technique works provided that you have pip installed and you have the required environmental variables.
Now, type in the following into the command prompt: 'python -m pip install "Path/To/Downloaded/File.py"'
Here's a real-life example: 'python -m pip install "C:/Users/danie/Downloads/pygame-1.9.3-cp36-cp36m-win_amd64.whl"'
If you have any errors, it would most likely because:
- (A) You don't have pip installed properly.
- (B) You gave an invalid directory branch.
- (C) You spelled something in the command wrong.
- (D) You forgot to download the Pygame module.
I hope this helps.
Pygame should be a dependency of turtle. Try to download pygame with pip.
More information about the installation:
https://www.pygame.org/wiki/GettingStarted
You've been working inside a Python standard library directory, placing your own files there and clobbering Python's insides. The error you're seeing is because you've edited or replaced the turtle.py from the standard library. At this point, there's no telling how much damage has occurred, and manually fixing things isn't going to be practical.
Uninstall and reinstall Python to restore things to normal, and stop putting your own work in that directory.
Seeing the error code you've posted, it seems that some files placed in the python directory have been messed with or there must have been some changes. Nevertheless, You can try doing an uninstall and then doing a clean install of python.
Then proceed to download pygame by:
pip install pygame
and then turtle module. You may have to look up for the Tkinter module too.
Hello there Stackoverflowers,
I am learning how to program with Pygame and I am trying to import pygame.locals
According to the tutorial I am learning from, I am starting of as such;
import pygame, sys
from pygame.locals import *
I get this error message:
Traceback (most recent call last): File "C:/Python33/test.py", line 2, in from pygame.locals import * ImportError: No module named 'pygame.locals'
I have downloaded Pygame (binary package) for Python 3.2, and I am currently running 3.3.
When I import pygame in the Python shell, no error is returned, and thus I am lead to believe that Pygame was successfully installed.
I am running Windows 7 64 Bit.
I've seen a similar post regarding pygame.locals and Raspberry Pi and Linux, so I think this post is still relevant. Let me know if it is not.
My guess is that you have a file named pygame.py in the current directory in which you are running you script.
I found that on Windows 7 64-bit, you need to get Python 3.3.5, as well as the pygame-1.9.2a0-hg version from Bitbucket.
This solved the problem ImportError: No module named 'pygame.locals' for me.
(Somehow it's a bit weird that the pygame website doesn't provide latest versions of pygame.)
yes #Bartlomiej Lewandowski, you were right.I also faced the same problem and came here to resolve it. I did not download any newer version as apt-get install was giving the message that this is the newest version.
I just renamed my file pygame.py to some other random name.
It is working fine now. So the problem was we named our file as pygame.py, Which is restricted in pygame module, I am not sure. But its working fine now.
Thanks Bartlomiej Lewandowski once again.
For RedHat I needed to install
yum install SDL-devel-1.2.14-7.el6_7.1.x86_64