Pygame is not importing [duplicate] - python

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!

Related

VS Code - Terminal not responding to input, Terminal running at wrong place, Pygame not installing [duplicate]

This question already has answers here:
How to install pygame?
(4 answers)
Unable to install Pygame using pip
(27 answers)
Closed 12 days ago.
This post was edited and submitted for review 12 days ago and failed to reopen the post:
Original close reason(s) were not resolved
VS Code not responding to ternimal input. Pygame will not install. Ternimal running place is wrong.
As of right now I am using two different computers hence the use of OneDrive (I know it's not optimal). Everything works absolutely fine on my other computer, including terminal input and pygame installation, running Python 3.11.2 MS Store version.
For the sake of this case I saved a py. file in the Downloads-folder (localy) and the terminal says that it is running from OneDrive, even though the file is not saved there.
I primarely use VS Code, but since this isn't working, I installed Spyder where pip works fine with minicoda.
Spyder Kernal/Console and pygame are working fine with conda: spyder-env (Python 3.10.9)
This is my first year learning Python so I'm really not sure what to do. My teacher is just as uncertain.
WHAT I HAVE TRIED:
VS Code:
I have tried re-installing VS Code by first deleting it completely. https://code.visualstudio.com/docs/setup/uninstall
Python:
I have tried re-innstalling Python with different versions.
Python: https://i.stack.imgur.com/ks7ND.png
Conda: https://i.stack.imgur.com/UDQyl.png
MS Store Python: https://i.stack.imgur.com/yfAAs.png

Can someone help me with my discord bot code error? [duplicate]

This question already has answers here:
How do I use installed packages in PyCharm?
(14 answers)
Closed 1 year ago.
When i run the code it says:
Traceback (most recent call last):
File "C:\Users\Gebruiker\PycharmProjects\pythonProject\DiscordBot.py", line 1, in
import discord
ModuleNotFoundError: No module named 'discord'
idk how to fix this, please help me.
You can install discord using:
pip install discord
If you are using anaconda, check your python interpreter from PyCharm. Go to File->Settings->Project Settings->Project Interpreter->Python Interpreters
Ensure to select correct version of python.exe
e.g.
For bare python (For this you need to install discord ) C:\Users\xxx\AppData\Local\Programs\Python\Python38\Lib
(a path similar to this)
For anaconda you'll see C:\Users\xxx\AppData\Local\Continuum\anaconda3\python.exe
Select the correct interpreter and you are good to go
In any case, i suggest you to take the time and learn about virtual environment
https://docs.python.org/3/library/venv.html

import pygame still not working even when downloaded [duplicate]

This question already has answers here:
ImportError: No module named 'pygame'
(25 answers)
Closed 1 year ago.
Im using vs code and when I write the command "pip install pygame" it tells me this "Requirement already satisfied: pygame in /usr/local/lib/python3.9/site-packages (2.0.1)" However, when I try to import pygame it doesnt work. It simply states "line 1, in <module> import pygame ImportError: No module named pygame"
If anyone can help me that would be awesome :)
I think you need to set up your virtual environment. https://code.visualstudio.com/docs/python/environments
But i would recommend you to you use PyCharm, when you create project it automatically creates venv for you and you dont need to care about it.

python module not found even though it is installed [duplicate]

This question already has answers here:
PyCharm error: 'No Module' when trying to import own module (python script)
(17 answers)
Closed 1 year ago.
I am using PyCharm and am having trouble importing modules
I set up a venv and imported the dependencies via pip install -r
When I try to run the application and get 'module not found' for all imports.
If I open a terminal in PyCharm and do pip list all the required modules are listed
Further PyCharm can file the modules - I can perform completion when typing the name of the module.
What else can I try?
Sounds like you have more than one python environment on your machine.
So, in my opinion, you need to manage the environments in python IDE.
The same happened to me so this helped me in that.
Do check: https://docs.python.org/3/tutorial/venv.html
You can also seek help from the below article:
https://www.freecodecamp.org/news/manage-multiple-python-versions-and-virtual-environments-venv-pyenv-pyvenv-a29fb00c296f/
I solved this by checking the boxes 'Add content toots to PYTONPATH' and #Add source roots to PYTHONPATH'

Python-Pygame Not Working [duplicate]

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

Categories

Resources