Why can't i import pygame on anaconda? - python

i'm trying import pygame on anaconda. I have try it by open spyder, type code as follows:
import pygame
Then something happens as follows:
Traceback (most recent call lasat):
file "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pygame'
I have done some research on google about this. i think it has something to do with this link: https://anaconda.org/CogSci/pygame.
I have download file on this link. but i don't know what to do about it.
Why can't i import pygame? How can i solve this problem?

The command listed earlier:
conda install -c cogsci pygame
will install pygame 1.9.2a0 which is an older package. I was able to find 1.9.5 at this channel:
conda install -c delichon pygame
But, since that version might be old by the time you read this, you might be better off going to https://anaconda.org/anaconda/repo and searching for pygame there. That way you'll be able to see which versions are available on which channel (like cogsci or delichon).

Forget about my last answer. I got what you're doing wrong. The modules/packages installations must happen in a cmd, not from the python shell. You're trying to install it from the python shell directly. Just open a cmd window and type
conda install pygame
and it should work.

Activate your environment
conda activate myenv
Install Pygame in Conda
conda install -c cogsci pygame

Go to the start menu > anaconda3 > anaconda prompt
in there type pip install pygame
I tried many solutions and this was the only one that worked for me.

Related

Pyautogui could not be resolved [duplicate]

I have read import error for pyautogui
and this did not answer my question.
I am trying to import pyautogui via the 3.5.2 shell or windows cmd. but when using the shell for:
import pyautogui
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pyautogui
ImportError: No module named 'pyautogui'
I have seen people say they resolved by using 3.5 but not for me. I have also seen people say that uninstalling and reinstalling can fix issues. I did this and on reinstall made sure that the path option was selected.
Step one: open windows cmd
Step two: and type in py -3.8 -m pip install pyautogui
You will most likely get a message that says: pip is not up to date, it would look like this: https://i.stack.imgur.com/DOfzQ.png
if you get this error Type in: py -m pip install --upgrade pip
Step three: Open: https://bootstrap.pypa.io/get-pip.py and copy everything on this page
Step four: Open IDLE and run what you just copied
Step five: Open windows cmd again and try py -3.8 -m pip install pyautogui again
Step six: Now try to run it again.
if this doesnt work please show us the errors you get.
Check that you are installing the package using the correct Python Version, in the documentation says that you have to install correspondant to your python version. In my case, I fixed it using python 3.9 (and making sure that my intepreter in VSC is set to Python 3.9.1)
Try doing pip install pyautogui and if it says all requirements are satisfied type in pip show pyautogui and if it shows then just try restarting your IDE and it should work

How can I fix the ImportError ("No module named pygame") on executing a python file?

After typing SnakeGame.py I am getting the error:
Traceback (most recent call last):
File "SnakeGame.py", line 1, in
import pygame
ImportError: No module named pygame).
Pls give me a solution on how to solve this, I have installed pygame also.
thanks in advance.
That error means that the python interpreter isn't able to find the pygame module.
Are you using a virtual environment? If you are using an IDE like PyCharm, try to install the pygame module inside the IDE console.
pip install pygame
install pygame in CMD write pip install pygame
if you use visual studio code go to market and type pygame then install it ...
enter image description here
visual studio code
I had this same problem a few days ago. My solution was to use a virtual environment. To do this, open a terminal in your folder and use the following commands: 1.) pip install pipenv 2.) pipenv shell 3.) pipenv install pygame
After this, you need to select the correct python interpreter. In VS Code, hit ctrl+shift+p Then click the correct interpreter (should have the name of the folder). Then try to run the file. If that doesn't work, try to run this in the terminal: pipenv run {name of the python file, example: app.py}
Hope that works for you

Pyautogui not importing "No module named 'pyautogui' "

import pyautogui
print("hello")
After running this I am presented with the following:
C:\Users\Darkm\Anaconda3\envs\PythonChallenges\python.exe C:/Users/Darkm/PycharmProjects/PythonChallenges/Automation1.py
Traceback (most recent call last):
File "C:/Users/Darkm/PycharmProjects/PythonChallenges/Automation1.py", line 1, in <module>
import pyautogui
ModuleNotFoundError: No module named 'pyautogui'
Process finished with exit code 1
Could somebody help me understand why I cannot import pyautogui?
Some background information:
1.) I only have one version of python (3.7.4)
2.) I have already installed the module through "pip install pyautogui" in cmd prompt.
3.) Pyautogui is installed under C:\Users\Darkm\Anaconda3\Lib\site-packages
4.) Pyautogui does not show up when I go into file > settings > project interpreter and try to add it
manually (it just doesn't show up).
5.) Have restarted computer multiple times
At this point I cannot figure out why I'm unable to import pyautogui, any help would be greatly appreciated!
Why are you getting this error?
Because you are using PyCharm.
In PyCharm you don't need to install python packages from command prompt, in PyCharm you need to install python packages from PyCharm Project Interpreter.
Here are some tips that can help you!
Step 1: Go to PyCharm settings and go to this directory: Preferences and select Interpreter Settings
Screenshot:
Step 2: Click on this plus icon.
Screenshot:
Step 3: Type your package name and select package.
Screenshot:
Step4: Then click on install button.
Step 5: Click on okay
Then wait for two to three minutes and try again.
Hopefully it'll work.
You and also do this trick on imports
import subprocess
try:
import pyautogui
except ImportError:
subprocess.call("pip install pyautogui")`
It's probably because of pycharm.
If it's not pycharm and you still have problems you can try:
Cmd:
python -m pip install < module >
To append to PYTHONPATH:
IDE:
import sys
sys.path.append('< path >')
If you face module not found on Jupyter environment you had to install it on Jupyter environment instead of installing it on command prompt
by this command (for windows)
!pip install pyautogui
After that you can easily import and use it.
Whenever you want to tell Jupyter that this is system command you should put ! before your command.
Make sure you have the latest version of python installed on your computer
On Windows:
Open up Windows PowerShell. Type py -m pip install pyautogui and wait for 2 minutes. Then, restart your IDE. Try running your code, it should work now.
On a Mac:
Open up iTerm. Type pip3 install pyautogui or py -m pip3 install pyautogui, and wait for 2 minutes. Then, restart your IDE. Then just simply try to run your code, it should be working.
Hope this helped!
Try this...
# Install a pip package in the current Jupyter kernel
import sys
!{sys.executable} -m pip install numpy
Tutorial from Pythonic Perambulations
Go to terminal.
type "pip install pyautogui"
pip install pyautogui
Your problem should be solved now.
If it isn't try this.
!pip install pyautogui
You are using Pycharm IDE. To install packages in Pycharm, you can use the project interpreter in settings or type the following in the terminal:
pip install pyautogui
make sure that library is installed in same version of python

My pygame will not work and i get this error: "ModuleNotFoundError: No module named 'pygame'" [duplicate]

I have installed python 3.3.2 and pygame 1.9.2a0. Whenever I try to import pygame by typing:
import pygame
I get following error message :
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import pygame
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pygame
ImportError: No module named 'pygame'
>>>
I went through some of the questions related to this error but none of the solution helped.
I have 64 bit machine with Win7 OS
go to python/scripts folder, open a command window to this path, type the
following:
C:\python34\scripts> python -m pip install pygame
To test it, open python IDE and type
import pygame
print (pygame.ver)
It worked for me...
Here are instructions for users with the newer Python 3.5 (Google brought me here, I suspect other 3.5 users might end up here as well):
I just successfully installed Pygame 1.9.2a0-cp35 on Windows and it runs with Python 3.5.1.
Install Python, and remember the install location
Go here and download pygame-1.9.2a0-cp35-none-win32.whl
Move the downloaded .whl file to your python35/Scripts directory
Open a command prompt in the Scripts directory (Shift-Right click in the directory > Open a command window here)
Enter the command:
pip3 install pygame-1.9.2a0-cp35-none-win32.whl
If you get an error in the last step, try:
python -m pip install pygame-1.9.2a0-cp35-none-win32.whl
And that should do it. Tested as working on Windows 10 64bit.
I was trying to figure this out for at least an hour. And you're right the problem is that the installation files are all for 32 bit.
Luckily I found a link to the 64 pygame download! Here it is: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame
Just pick the corresponding version according to your python version and it should work like magic. The installation feature will bring you to a bright-blue screen as the installation (at this point you know that the installation is correct for you.
Then go into the Python IDLE and type "import pygame" and you should not get any more errors.
Props go to #yuvi who shared the link with StackOverflow.
open the folder where your python is installed
open scripts folder
type cmd in the address bar. It opens a command prompt window in that location
type pip install pygame and press enter
it should download and install pygame module
now run your code. It works fine :-)
I had the same problem and discovered that Pygame doesn't work for Python3 at least on the Mac OS, but I also have Tython2 installed in my computer as you probably do too, so when I use Pygame, I switch the path so that it uses python2 instead of python3. I use Sublime Text as my text editor so I just go to
Tools > Build Systems > New Build System and enter the following:
{
"cmd": ["/usr/local/bin/python", "-u", "$file"],
}
instead of
{
"cmd": ["/usr/local/bin/python3", "-u", "$file"],
}
in my case. And when I'm not using pygame, I simply change the path back so that I can use Python3.
The current PyGame release, 1.9.6 doesn't support Python 3.9. I fyou don't want to wait for PyGame 2.0, you have to use Python 3.8. Alternatively, you can install a developer version by explicitly specifying the version (2.0.0.dev20 is the latest release at the time of writing):
pip install pygame==2.0.0.dev20
or try to install a pre-release version by enabling the --pre option:
pip install pygame --pre
Resolved !
Here is an example
C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame
try this in your command prompt:
python -m pip install pygame
I was getting the same error. It is because your version of Pygame is not compatible with your version of Python or Pydev. Go to this link and get the proper version of Pygame for your current version of Python. Ctrl F to find it faster or click on the word python in blue. up at the top. While you instal Pygame it should find the Python path by itself. At least mind did any ways. I run Pygame through Eclipse with Python 3.4.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Since no answer stated this:
Make sure that, if you are using a virtual environment, you have activated it before trying to run the program.
If you don't really know if you are using a virtual environment or not, check with the other contributors of the project. Or maybe try to find a file with the name activate like this: find . -name activate.
Install and download pygame .whl file.
Move .whl file to your python35/Scripts
Go to cmd
Change directory to python scripts
Type:
pip install pygame
Here is an example:
C:\Users\user\AppData\Local\Programs\Python\Python36-32\Scripts>pip install pygame
I just encountered the same problem and found that I am having multiple interpreters of the different versions installed in my system and pygame got installed in one of them when I installed it using command but in my IDE another interpreter was selected so this messed up my system, try to see if you are also having the same situation.
Just use this command in the terminal python3 -m pip install -U pygame --user
I am a quite newbie to python and I was having same issue. (windows x64 os)
I have solved, doing below steps
I removed python (x64 version) and pygame
I have downloaded and installed python 2.6.6 x86: https://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
I have downloaded and installed pygame (when installing, I have chosen the directory that I installed python): http://pygame.org/ftp/pygame-1.9.1.win32-py2.6.msi
Works well :)
You don't need 64 bit Python on Win64 system, just install the 32bit versions of both Python and Pygame and they will work just fine (and there is a ton more modules for them anyways).
I’m using the PyCharm IDE. I could get Pygame to work with IDLE but not with PyCharm. This video helped me install Pygame through PyCharm.
https://youtu.be/HJ9bTO5yYw0
(It seems that PyCharm only recognizes a package; if you use its GUI.)
However, there were a few slight differences for me; because I’m using Windows instead of a Mac.
My “preferences” menu is found in: File->Settings…
Then, in the next screen, I expanded my project menu, and clicked Project Interpreter. Then I clicked the green plus icon to the right to get to the Available Packages screen.
I ran into the error a few days ago! Thankfully, I found the answer.
You see, the problem is that pygame comes in a .whl (wheel) file/package. So, as a result, you have to pip install it.
Pip installing is a very tricky process, so please be careful. The steps are:-
Step1. Go to C:/Python (whatever version you are using)/Scripts. Scroll down. If you see a file named pip.exe, then that means that you are in the right folder. Copy the path.
Step2. In your computer, search for Environment Variables. You should see an option labeled 'Edit the System Environment Variables'. Click on it.
Step3. There, you should see a dialogue box appear. Click 'Environment Variables'. Click on 'Path'. Then, click 'New'. Paste the path that you copies earlier.
Step4. Click 'Ok'.
Step5. Shift + Right Click wherever your pygame is installed. Select 'Open Command Window Here' from the dropdown menu. Type in 'pip install py' then click tab and the full file name should fill in. Then, press Enter, and you're ready to go! Now you shouldn't get the error again!!!
First execute python3 then type the command import pygame,now you can see the output
For this you have to install pygame package from the cmd (on Windows) or from terminal (on mac). Just type pip install pygame
.If it doesn't work for you, then try using this statement pip3 install pygame .
If it is still showing an error then you don't have pip installed on your device and try installing pip first.
make sure if you are on windows that your library directory is added to path
This may happen when pygame didn't installed, install the pygame first
pip
pip install pygame
if dont work update the PIP by goto python install folder and type
python -m pip install --upgrade pip
hope it work
Try this solution:
Type in to cmd (Windows):
C:\Users\'Your name'> pip install -U pygame
You should remove python -m, py -m, python3 -m before the pip
Also remove --user behind it.
It will said:
C:\Users\viait>pip install -U pygame
Defaulting to user installation because normal site-packages is not writeable
Collecting pygame
Downloading pygame-2.1.2-cp310-cp310-win_amd64.whl (8.4 MB)
---------------------------------------- 8.4/8.4 MB 1.7 MB/s eta 0:00:00
Installing collected packages: pygame
Successfully installed pygame-2.1.2
Then test it in your IDE or cmd:
(CMD example)
C:\Users\viait>python
Python 3.10.3 (tags/v3.10.3:a342a49, Mar 16 2022, 13:07:40) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.1.2 (SDL 2.0.18, Python 3.10.3)
Hello from the pygame community. https://www.pygame.org/contribute.html
(IDE example)
import pygame
You can do this without any errors.
You could use
pip install pygame
but if you use IDE like PyCharm, then you could just either install it from Python Packages or use right click at the package name then left click on Show Context Actions then left click on Install package pygame
(Personally, I recommended using Python Packages for the package installing because it has documentation with it)
You gotta use Pycharm and install it in Terminal using pip install pygame and also after that enter Pycharm and hover on pygame in the "Import pygame" and in Pycharm it will tell you to download that and you can easily download it and enjoy your result
I was having the same trouble and I did
pip install pygame
and that worked for me!

Unable to import pyautogui

I have read import error for pyautogui
and this did not answer my question.
I am trying to import pyautogui via the 3.5.2 shell or windows cmd. but when using the shell for:
import pyautogui
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pyautogui
ImportError: No module named 'pyautogui'
I have seen people say they resolved by using 3.5 but not for me. I have also seen people say that uninstalling and reinstalling can fix issues. I did this and on reinstall made sure that the path option was selected.
Step one: open windows cmd
Step two: and type in py -3.8 -m pip install pyautogui
You will most likely get a message that says: pip is not up to date, it would look like this: https://i.stack.imgur.com/DOfzQ.png
if you get this error Type in: py -m pip install --upgrade pip
Step three: Open: https://bootstrap.pypa.io/get-pip.py and copy everything on this page
Step four: Open IDLE and run what you just copied
Step five: Open windows cmd again and try py -3.8 -m pip install pyautogui again
Step six: Now try to run it again.
if this doesnt work please show us the errors you get.
Check that you are installing the package using the correct Python Version, in the documentation says that you have to install correspondant to your python version. In my case, I fixed it using python 3.9 (and making sure that my intepreter in VSC is set to Python 3.9.1)
Try doing pip install pyautogui and if it says all requirements are satisfied type in pip show pyautogui and if it shows then just try restarting your IDE and it should work

Categories