import pygame no module named 'pygame' [duplicate] - python

This question already has answers here:
Python error "ImportError: No module named"
(37 answers)
Closed 3 years ago.
I'm using a mac and typed
pip install pygame
into my terminal.
The terminal said the download was successful, but when I use
import pygame
in IDLE, I get an error.
I've looked at questions similar to this one and have not found an answer. Does anyone know what the problem could be?

Your terminal is referring to a different environment that the one that your IDLE environment refers to. For example Pycharm saves its python packages in the venv folder by default. Pip installing a package through the terminal would not allow you to import the package inside pycharm because you have not installed it in the venv environment.
To fix this, I believe you should use the command
source activate
in order to activate the environment that IDLE is running. You should be able to install it, and import it then.

Related

What can I do to install Pygame? [duplicate]

This question already has answers here:
How to install pygame?
(4 answers)
Unable to install Pygame using pip
(27 answers)
Closed 22 days ago.
I can't use pygame package in Pycharm. I have installed it with pip but I can not use it. When I tried to install it from the error that appeared in the IDE or from 'Python Packages', it gave me an error. I also tried pip install pygame --pre and it's not working. It says that 'Requirement already satisfied:' but I still can not use it. What should I do?
You should be able to left click on the module. It will display a download packages button. You need internet but should be able to download it. You don't to use the command prompt to install packages. That is only for the python IDLE.
Go here and click install. Pycharm using his own registry of packages.
https://imgur.com/a/AZvsBxJ
So, you're using PyCharm, it likely means it has created a new virtual environment when you created your project, to install packages in that environment it's easiest to either use PyCharm's Package Manager or Terminal. In the case of using Python 3.11 you'd need to supply the --pre flag when installing pygame because the full release of 2.1.3 has not yet been released and 2.1.3.dev8 which is a pre release is the latest one that has 3.11 wheels for installation. More information about that particular thing can be found here: https://stackoverflow.com/a/74188087/14531062
So, on PyCharm you'd want to use the Terminal:
When you switch to it, you'll likely find that it basically is PowerShell (unless you have changed it to use CMD which I doubt) (you'll see PS at the start of each line) so the easiest steps to install pygame would be to type in these commands in this order (press the enter key after each line):
cmd
venv\scripts\activate
pip install pygame --pre
After running these commands pygame should be installed in the correct environment and you should be able to import it without any issues.
Screenshot of how it might look when you follow the steps:

No module named "pygame" after using pip

I am a beginner and I want to work with the pygame module. I have already used pip install to install pygame and it says so on my command prompt. On my command prompt it says:
Requirement already satisfied: pygame in c:\users\35192\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages (2.1.2)
However, when I try to import pygame in vscode, the module won't import and it says: "ModuleNotFoundError: No module named 'pygame'"
Does anyone know how to fix this?
I solved the problem. I basically just used Ctrl+Shift+P to open up the command palette. From there, I opened "Python: Select interpreter" and then I just changed the python interpreter to be the global one (which I assume is the one used by the command prompt)
As seen here: https://stackoverflow.com/questions/15185827/can-pip-be-used-with-python-tools-in-visual-studio#:~:text=Go%20to%20Tools%20-%3E%20Python%20Tools%20-%3E%20Python,enter%20your%20module%20and%20double%20click%20to%20install.
You have to go to Tools -> Python Tools -> Python Environments in vs code. Then click on your python installation, then pip, and install pygame.
Or you can find where your vs code python installation is, and run this: "directory to vs code python.exe" -m pip install pygame
If you would like to use one python installation everywhere, you can change your vs code interpreter/environment to the python you already have installed on your system. As seen here: https://code.visualstudio.com/docs/languages/python

pip install pyodbc is not working on python [duplicate]

This question already has answers here:
Why does "pip install" inside Python raise a SyntaxError?
(7 answers)
Closed 2 years ago.
I installed Python on my Windows 10 computer
when I try to run my python code
I get error
ModuleNotFoundError: No module named 'pyodbc'
I checked multiple questions here and the solution is to pip pyodbc
I tried that
pip install pyodbc
but i get error
SyntaxError: invalid syntax
I checked similar propblems here and it seems that pip is not installed.
I unistalled and reinstalled python from python.org and still same issue!
any solution?
Edit
I did as suggested to try from command prompt
but still same error
I installed Python with ticking the option to include environment variables option.
Edit 2 :
I think the problem was that I was trying to install from witthin python.
I misunderstood the answers, I have to run pip as an application outside of python. to allocate pop.exe and then do pip install.
You are trying to install the package from python interpreter (IDLE) which is wrong. You should only import package from IDLE terminal (python session) which IDLE has access to.
Try this link to install the package --> https://pip.pypa.io/en/latest/installing/
You would run pip from a shell, not from the IDLE. However, pyodbc requires the Microsoft ODBC Driver. More information about installing the pyodbc module can be seen in this guide. This Stack Overflow answer can also help.
Normally, you run pip from a shell, not from a Python interactive session.
C:\PATHTOPYTHON\python.exe pip install <<SOMEPACKAGE>>
See the following thread, if you want to install from within a Python interactive session.

ModuleNotFoundError, but the package should be there [duplicate]

This question already has answers here:
ModuleNotFoundError: No module named 'requests' after pip install [duplicate]
(2 answers)
Closed 1 year ago.
Here is what I'm using:
Python 3.7.x on PyCharm 2018.2.4
Windows 10.
I'm following a tutorial about website parsing, but the struggle begins before I can even really start out.
I get the error message:
ModuleNotFoundError: No module named 'requests'
The package should be installed properly (pip3 install requests) and I run only that single version of python as far aI i know. I can find the package in the directory I'd expect it to be (C:\Users\Bob\AppData\Local\Programs\Python\Python37\Lib\site-packages).
I expect the same problem for the other package (beautifulsoup4), but the script doesn't even get that "far".
So, I'm aware that I must've done something incorrectly but I can't figure out what.
Any advice?
requests is a module which is needed for the script / the command you are trying to run but seems not to be part of the python installation or the python distribution you choose.
I can guess that you got the error while entering the following line:
>>> import requests
I would run the pip install request command from powershell and try to install the package:
python -m pip install requests
I do not know what you want to use python for but I usually advise to use a python distribution such as Anaconda which contains plenty of additional packages including requests.

Why ipython Anaconda does not recognize my omdb import? [duplicate]

This question already has an answer here:
Anaconda not finding my packages installed with `pip`
(1 answer)
Closed 6 years ago.
I am having some issues understanding what is happening with the installation of omdb module in my computer (https://github.com/dgilland/omdb.py).
I installed via Terminal using:
pip install omdb
Then I created a simple python script to test if it would import correctly:
import matplotlib
import omdb
print omdb.get(title='A Beautiful Mind', fullplot=True, tomatoes=True)
The script ran perfectly when I used python in terminal:
python movies.py
but then I tried to use my ipython with Anaconda, and I would always get the following message:
ImportError: no module named omdb
Is there another way to install a module, or am I missing something about Anaconda and Python?
All I wanted was to be able to use omdb. I'm using Python 2.7.11-0 and OS X 10.9.5. Any help is appreciated
That's because Anaconda installed packages aren't stored into a Python library, it has it's own warehouse. So you should use the command for it:
conda install omdb
Anaconda comes with its own package manager named conda. It also doubles as a virtual environment manager.
The Python package manager is pip, which is only a package manager and you will have to install virtualenv in order to manage virtual environments.

Categories

Resources