My IDLE says Pygame has not been installed even though I have? - python

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.

Related

Why is Atom only allowing me to use the standard python library

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

VS Code ipython/jupyter interactive environment not showing full traceback?

Not sure if this is a VS code or Jupyter problem but I have been using Jupyter in VS Code (specifically using the "# %%" implementation outlined here).
I noticed recently that my error tracebacks are not showing the full traceback, but rather only the first layer.
For example, I made a simple dummy error (hiding my path on purpose here):
ran in interactive mode:
NameError
Traceback (most recent call last)
[PATH] in <module>
----> 97 py_getAnnotation(["a", "b"])
[PATH] in py_getAnnotation(experiments)
NameError: name 'hold_s' is not defined
But running script normally:
Traceback (most recent call last):
File [PATH], line 97, in <module>
py_getAnnotation(["a", "b"])
File [PATH], line 77, in py_getAnnotation
hold_s.name = col
NameError: name 'hold_s' is not defined
I recently had to switch from Mac to Windows. So I am not sure if this is a VS Code thing, an iPython setting/version thing, or maybe even an OS-specific thing.
I've never had this happen before. Any ideas would be appreciated.
NOTE:
I tried uninstalling ipython dependencies and reinstalling.
I have tried running %xmode as suggested in an old post
Edit: I have also copied and pasted my code into a jupyter notebook at that error traceback is fine. So seems to be VS Code Specific.
Edit: Downgrading VS Code to an earlier version worked! But if anyone has an idea why it happened in the first place that would be appreciated.

Unable to initialize Pygame display, but only when running through tox

I have the following, minimal test program.
import pygame
pygame.init()
print(pygame.display.list_modes())
If I try to run this program via a Tox command, I get the error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(pygame.display.list_modes())
pygame.error: video system not initialized
However, if I activate the virtual environment the tox command runs in and run the same program manually, it works as expected. I would expect both execution environments to be the same. What am I doing wrong?
In order to fix the problem I needed to add a
passenv = DISPLAY
to my [testenv].
As mentioned in the comment above, tox does an isolated build, and does not pass in ENVIRONMENT variables, except you whitelist them.
I am not super familiar with pygame, I just had a quick look in the source.
This works on my machine with Ubuntu - maybe it is different for your setup.

Problems with pywikibot in PyCharm

Henlo everyone,
I met a very specific problem with my Python installation. I have a PyCharm project using a venv with pywikibot installed. Whenever I try to import the module, I get the following error:
Traceback (most recent call last):
File "C:/Users/<username>/<path to project>/alphabets/coptic_characters.py", line 1, in <module>
import pywikibot as pwb
File "C:\Users\<username>\<path to project>\venv\lib\site-packages\pywikibot\__init__.py", line 15, in <module>
from decimal import Decimal
File "C:\Users\<username>\Anaconda3\lib\decimal.py", line 3, in <module>
from _decimal import *
AttributeError: module 'numbers' has no attribute 'Number'
It appears to have broken itself because earlier in the day it worked with no problems.
I also have the module installed on a global Anaconda3 setup elsewhere in my computer. It works fine everywhere except, that's where it gets weird, when I try to execute it inside the project directory. It gets even stranger than that, if I execute the interpreter in a sub-folder, it works again. I don't understand what's happening here at all…
I tried creating a new project but I get the same error and behavior.
What am I missing? I don't understand why it stopped working suddenly event though I did nothing to the venv.
P.S.: I'm on Windows 10.
So !
It appears that a module I created with the name numbers was interfering with Python's code. I just changed the name and it suddenly worked again !
Thanks to #furas for suggesting this.

Pygame won't import to python

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.

Categories

Resources