This question already has answers here:
ImportError: No module named 'pygame'
(25 answers)
Closed last year.
I installed python(2.7) using anaconda on an ubuntu machine.
I installed pygame.
When I import pygame I get the error:
ImportError: No module named pygame
Interestingly, when I use /usr/bin/python,
the interpreter now gives no error for import python.
My code file has to run by command python x.py, not in te interpreter.
How could I resolve the issue?
Many Thanks.
Which version are you using? You most import pygame to a Python 2.7 shell.
http://pygame.org/download.shtml is for https://www.python.org/ version 2.7. Make sure you have downloaded and made the setup for Python 2.7 before you coming over and import pygame. If you have followed my steps, I hope you will see:
>>>
Pygame only works for python 2.7 and down. If you downloaded a later version make sure you go into setting in pygame and make sure you have selected python 2.7 to run. You can also do this by making a new project and when you name it scroll down to base interpreter and select python 2.7 since pygames will most likely have selected a higher version of python which will not work for pygames
Related
this might be a very stupid question but I'm a beginner.
I want to use this package called colorgram, it's a module that extracts colours from images, and I installed it using pip via the CMD. but when I try to import it in VS code it can't find it and I don't know what to do, please help
#Andrii Zadaianchuk
sorry, I'm using windows 10. I tried to import it in python in the CMD but nothing either, just the same ModuleNotFoundError: No module named 'colorgram' error.
I did just notice that the modules python version is 3.5 and VS code is running 3.9.2. I think that might be the problem
This question already has answers here:
Pylint "unresolved import" error in Visual Studio Code
(40 answers)
PyLint "Unable to import" error - how to set PYTHONPATH?
(33 answers)
Imports failing in VScode for pylint when importing pygame
(3 answers)
Closed 1 year ago.
I’ve downloaded pygame but VS code says, in the problems section , it is “Unable to import ’pygame’ pylint(import-error)”
In the terminal it says “ModuleNotFoundError: No module named ‘pygame’”
What could be causing it to not import?
Edit: I added some more specifics
I'm pretty new to python, but I'll try to give you a solution.
You could create a virtual environment in your terminal. If you don't know how to do that, here's a link to a website I found for macos, https://sourabhbajaj.com/mac-setup/Python/virtualenv.html. For windows, https://mothergeo-py.readthedocs.io/en/latest/development/how-to/venv-win.html. Activate the virtualenv, and then pip install pygame inside the virtualenv, so when you run your code, pygame should work as long as the virtualenv you downloaded pygame in is activated.
I really hope this helps as this is my first time answering a question on stackoverflow!
so im using visual code,
have python 3.8 installed and i installed the pygame package from powershell,
yet when im writing pygame code it gives me the next error:
" ModuleNotFoundError: No module named 'pygame' "
tried everything for hours cant get it to work
help will be apriciated <3
images:
What you also can do is to download pygame to your folder and than run the command python setup.py. This should install everythin correctly. If you still have trouble using pygame you can use the files in src_py from the download:
import init #instead of pygame.init()
I hope I was able to help.
I installed Pygame on my mac using Anaconda.
pip install pygame
>>>Requirement already satisfied: pygame in /anaconda/lib/python3.6/site-packages
The thing is, I do not know to use it now. When I run a simple file from my code editor it says:
File "/Users/julien/untitled5.py", line 1, in <module>
import pygame
ImportError: No module named pygame
any advice ? I tried to run pygame using spyder from the Ananconda Navigator bun it does not seem to work either.
The issue is that your IDE is looking in the wrong places for pygame. To see where it's looking for packages, run this script in the console for that IDE:
>>>import sys
>>>sys.path
This will show a list of paths where python looks for packages. /anaconda/lib/python3.6/site-packages won't be there, which is why you can't import it. What IDE are you using? Most are able to change their settings so that they can import from different places, see if you can do that, and put /anaconda/lib/python3.6/site-packages as part of the path.
This question already has answers here:
Python Interpreter Mode - What are some ways to explore Python's modules and its usage
(3 answers)
Closed 8 years ago.
OS Windows XP SP3
situation
I installed three python exes on my machine.
Python 2.6
Python 2.7
Python EPD ENABLED (for pylab)
problem
I installed wxPython and in the selection I decided to install it to Python in system registry
I don't know to which python this package was installed.
what I tried
I tried writing import wx on all the shells and found that it was installed to EPD python.
bigger issue
I don't want to keep doin this each time I install a package. So is there a command that can be used in the shell or any other way, so that I can know about all the packages installed?
please help me with this issue.
Type help() in the shell. And then in the help prompt type modules to see a complete list of all modules.
You can get a complete list with sys.builtin_module_names and pkgutil.walk_packages():
import pkgutil
import sys
print sys.builtin_module_names + [name for module_loader, name, ispkg in pkgutil.walk_packages()]
The modules subcommand of help() puts a friendlier interface on top of these results.