ModuleNotFoundError: No module named 'pygame' - python-3.x

I have python 3.7 with 32bit and after I did pip install pygame, I'm still getting
ModuleNotFoundError: No module named 'pygame'
when running my code. I'm using pycharm.

I would just like to add to what the first answer is saying:
If you are using pycharm, it still won't work until you go to file >> settings >> >> [your project name] >> python interpreter. You will see a list of packages there. If pygame is on it, then good, else, you must double click on the field where the packages are. It leads you to a little pop up box where you can type in things. If you type in pygame, you should be able to install the package.

To be sure that you installed the python3 proper module u need to use
pip3 install pygame

I ran into the same 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 copied 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!!!

Probably you have several instances of Pythion on your computer. You may install pygame in one instance, but IDE uses another.

Related

Google images search API raising ModuleNotFoundError for curses on windows [duplicate]

In PyCharm, I've added the Python environment /usr/bin/python. However,
from gnuradio import gr
fails as an undefined reference. However, it works fine in the Python interpreter from the command line.
GNURadio works fine with python outside of Pycharm. Everything is installed and configured how I want it.
Gnuradio is located at /usr/local/lib/python2.7/site-packages/gnuradio
Also:
PYTHONPATH=/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/gnuradio
Adding a Path
Go into File → Settings → Project Settings → Project Interpreter.
Then press configure interpreter, and navigate to the "Paths" tab.
Press the + button in the Paths area. You can put the path to the module you'd like it to recognize.
But I don't know the path..
Open the python interpreter where you can import the module.
>> import gnuradio
>> gnuradio.__file__
"path/to/gnuradio"
Most commonly you'll have a folder structure like this:
foobarbaz/
gnuradio/
__init__.py
other_file.py
You want to add foobarbaz to the path here.
You should never need to modify the path directly, either through environment variables or sys.path. Whether you use the os (ex. apt-get), or pip in a virtualenv, packages will be installed to a location already on the path.
In your example, GNU Radio is installed to the system Python 2's standard site-packages location, which is already in the path. Pointing PyCharm at the correct interpreter is enough; if it isn't there is something else wrong that isn't apparent. It may be that /usr/bin/python does not point to the same interpreter that GNU Radio was installed in; try pointing specifically at the python2.7 binary. Or, PyCharm used to be somewhat bad at detecting packages; File > Invalidate Caches > Invalidate and Restart would tell it to rescan.
This answer will cover how you should set up a project environment, install packages in different scenarios, and configure PyCharm. I refer multiple times to the Python Packaging User Guide, written by the same group that maintains the official Python packaging tools.
The correct way to develop a Python application is with a virtualenv. Packages and version are installed without affecting the system or other projects. PyCharm has a built-in interface to create a virtualenv and install packages. Or you can create it from the command line and then point PyCharm at it.
$ cd MyProject
$ python2 -m virtualenv env
$ . env/bin/activate
$ pip install -U pip setuptools # get the latest versions
$ pip install flask # install other packages
In your PyCharm project, go to File > Settings > Project > Project Interpreter. If you used virtualenvwrapper or PyCharm to create the env, then it should show up in the menu. If not, click the gear, choose Add Local, and locate the Python binary in the env. PyCharm will display all the packages in the selected env.
In some cases, such as with GNU Radio, there is no package to install with pip, the package was installed system-wide when you install the rest of GNU Radio (ex. apt-get install gnuradio). In this case, you should still use a virtualenv, but you'll need to make it aware of this system package.
$ python2 -m virtualenv --system-site-packages env
Unfortunately it looks a little messy, because all system packages will now appear in your env, but they are just links, you can still safely install or upgrade packages without affecting the system.
In some cases, you will have multiple local packages you're developing, and will want one project to use the other package. In this case you might think you have to add the local package to the other project's path, but this is not the case. You should install your package in development mode. All this requires is adding a setup.py file to your package, which will be required anyway to properly distribute and deploy the package later.
Minimal setup.py for your first project:
from setuptools import setup, find_packages
setup(
name='mypackage',
version='0.1',
packages=find_packages(),
)
Then install it in your second project's env:
$ pip install -e /path/to/first/project
For me, it was just a matter of marking the directory as a source root.
Add path in PyCharm 2017
File -> Settings (or Ctrl+Alt+S) -> Project -> Project Interpreter
Show all
Select bottom icon on the right side
Click on the plus button to add new path to your module
My version is PyCharm Professional edition 3.4, and the Adding a Path part is different.
You can go to "Preferences" --> "Project Interpreter". Choose the tool button at the right top corner.
Then choose "More..." --> "Show path for the selected interpreter" --> "Add". Then you can add a path.
DON'T change the interpreter path.
Change the project structure instead:
File -> Settings -> Project -> Project structure -> Add content root
In PyCharm 2020.1 CE and Professional, you can add a path to your project's Python interpreter by doing the following:
1) Click the interpreter in the bottom right corner of the project and select 'Interpreter Settings'
2) Click the settings button to the right of the interpreter name and select 'Show All':
3) Make sure your project's interpreter is selected and click the fifth button in the bottom toolbar, 'show paths for the selected interpreter':
4) Click the '+' button in the bottom toolbar and add a path to the folder containing your module:
For PyCharm Community Edition 2016.3.2 it is:
"Project Interpreter" -> Top right settings icon -> "More".
Then on the right side there should be a packages icon. When hovering over it it should say "Show paths for selected interpreter". Click it.
Then click the "Add" button or press "alt+insert" to add a new path.
As quick n dirty fix, this worked for me:
Adding this 2 lines before the problematic import:
import sys
sys.path.append('C:\\Python27\\Lib\site-packages')
On Project Explorer, you can right click on the folder where the module is contained and set as 'Source'.
It will be parsed in the Index for code completion as well as other items.
I'm new to PyCharm (using 2018.3.4 CE) and Python so I rotely tried to follow each of the above suggestions to access the PIL (Pillow) package which I knew was in system-site-packages. None worked. I was about to give up for the night when I happened to notice the venv/pyvenv.cfg file under my project in the Project Explorer window. I found the line "include-system-site-packages = false" in that file and so I changed it to "true". Problem solved.
In my PyCharm 2019.3, select the project, then File ---> Settings, then Project: YourProjectName, in 'Project Interpreter', click the interpreter or settings, ---> Show all... ---> Select the current interpreter ---> Show paths for the selected interpreter ---> then click 'Add' to add your library, in my case, it is a wheel package
For me there is also another issue. If you try to add a folder that in the past had a .idea folder, but your current project has it's own .idea folder your pycharm might get confused for some reason -- even if you have the right python/conda env. For me deleting the .idea folder of the other project fixed the confusion that it could find the obviously correctly installed pkgs. Then it was it was able to find them in the pycharm editor GUI snf stopped underlyinging them in red.
Download anaconda
https://anaconda.org/
once done installing anaconda...
Go into Settings -> Project Settings -> Project Interpreter.
Then navigate to the "Paths" tab and search for /anaconda/bin/python
click apply

How to open and view CGNS files on Windows 10 after installing PyCGNS python package?

After installing PyCGNS python package from Anaconda distribution, I am not able to open CGNS files as recommended in the following pages using the command line CGNS.NAV or cg_look:
Browsing your CGNS tree with NAV
Here is the error message I am receiving whether I am running the command line in Git Bash, Powershels, or CMD:
CGNS.NAV: FATAL error, cannot import qtpy.QtCore...
Hints:
pyqt5 is already installed
print(sys.path)
'C:\\ProgramData\\Anaconda3\\Scripts', 'C:\\ProgramData\\Anaconda3\\python38.zi
p', 'C:\\ProgramData\\Anaconda3\\DLLs', 'C:\\ProgramData\\Anaconda3\\lib', 'C:\\
ProgramData\\Anaconda3', '', 'C:\\ProgramData\\Anaconda3\\lib\\site-packages', '
C:\\ProgramData\\Anaconda3\\lib\\site-packages\\vboxapi-1.0-py3.8.egg', 'C:\\Pro
gramData\\Anaconda3\\lib\\site-packages\\win32', 'C:\\ProgramData\\Anaconda3\\li
b\\site-packages\\win32\\lib', 'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\
Pythonwin', 'C:\\ProgramData\\Anaconda3\\lib\\site-packages\\IPython\\extensions
', 'C:\\Users\\user_name\\.ipython']
You need to install PyQT.
Open the cmd.exe prompt from the anaconda navigator (in the home menu).
Execute this command:
conda install pyqt5
If you already had install it, maybe it's not in your enviroment.
Please post the output from:
print(sys.path)
Find out where PyQt5 is installed and ad it to your path-enviroment. You will find plenty of howto's in the internet. Here is one of them (Source: https://www.educative.io/edpresso/how-to-add-python-to-path-variable-in-windows):
Right-clicking This PC and going to Properties.
Clicking on the Advanced system settings in the menu on the left.
Clicking on the Environment Variables button o​n the bottom right.
In the System variables section, selecting the Path variable and clicking on Edit. The next screen will show all the directories that are currently a part of the PATH variable.
Clicking on New and entering Python’s install directory.

Trouble installing a new package using Anaconda Prompt

I'm trying to install a package 'backtesting' in my Anaconda prompt by typing 'pip install backtesting' but getting EnvironmentError......
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'c:\users\james\appdata\local\continuum\anaconda3\lib\site-packages\~il\_imaging.cp36-win_amd64.pyd'
Consider using the --user option or check the permissions.
How do I 'Consider using the --user option or check the permissions.'? Many thanks in advance
please try using below:
pip install backtesting --user
I tried it and successfully installed the package.
The above answer is the correct '--user' usage.
I find when I cannot install with conda or pip keywords, I simply add the module to the environment variables.
You can do this by accessing your search field on your taskbar and type 'Environment variable' (minus the single quotes) which will produce a window allowing you the option to edit environment vars.
Or you can go directly to 'System Properties' and select the 'Advanced' tab. On the bottom right is a button for environment variables. Clicking on environment variables
you are taken to a new window.
Selecting 'New' from the 'System Variables' field, you want to add the full path of your project solution and once saved your program can 'see' the module. The clincher is you must restart your computer after adding the variable, once the computer is back up the edited 'Environment Variable' becomes effective. You will be able to use the import statement like you always do at the start of program without the error.

PyCharm does not find pygame [duplicate]

I've downloaded pygame-1.9.1release.tar.gz from the Pygame website. I extracted and installed it and it's working fine in the command line Python interpreter in Terminal (Ubuntu). But I want to install it for some IDE, like PyCharm. How can I do it?
Well, you don't have to download it for PyCharm here. You probably know how it checks your code. Through the interpreter! You don't need to use complex command lines or anything like that. You need to is:
Download the appropriate interpreter with PyGame included
Open your PyCharm IDE (Make sure it is up to date)
Go to File
Press Settings (Or Ctrl + Alt + S)
Double click on the option that looks like Project: Name_of_Project
Click on Project Interpreter
Choose the interpreter you want to use that includes PyGame as a module
Save your options
And you are ready to go! Here is an alternate (I have never done this, please try to test it)
Add PyGame in the same folder as your PyCharm file (Your PyCharm stuff is always in
a specific file placed by you during installation/upgrade)
Please consider putting your PyCharm stuff inside a folder for easy access.
I hope this helps you!
For PyCharm 2017 do the following:
File - Settings
Double click on your project name
Select Project Interpreter
Click on green + button on the right side of the window
Type Pygame in search window
Click Install package.
Not I'm saying that the answers above won't work, but it might be frustrating to a newbie to do command line magic.
If you are using PyCharm and you are on a Windows 10 machine use the following instructions:
Click on the Windows start menu and type cmd and click on the Command Prompt icon.
Use the command pushd to navigate to your PyCharm project which should be located in your user folder on the C:\ drive. Example: C:\Users\username\PycharmProjects\project name\venv\Scripts.
(If you are unsure go to the settings within PyCharm and navigate to the Python Interpreter settings. This should show you the file path for the interpreter that your project is using. Credit to Anthony Pham for instructions to navigate to interpreter settings.)
HINT: Use copy and paste in the command prompt to paste in the file path.
Use the command pip install pygame and the pip program will handle the rest for you.
Restart you Pycharm and you should now be able to import pygame
Hope this helps. I had a fun time trying to find out the correct way to get it installed, so hopefully this helps someone out in the future.
I just figured it out!
Put the .whl file in C:\Program Files\Anaconda3
While in the folder, click on the blue File tab in the upper left corner of the Window Explorer (assuming you're using Windows)
Click on Open Windows PowerShell as administrator
Write or just copy and paste: py -m pip install pygame
It should start installing
Done!
I hope it works for you. I know it did for me.
I already had pygame installed with python38-32
since its working just fine with it. I used this version of python us my project interpreter.
1.File -settings
2.according to your settings look for project interpreter
3.click on your current project interpreter and click on the add symbol
4.choose system interpreter
5.select the python version thats works with pygame for you
6.Note: some versions of pygame don't work with some versions of python be sure
of what are you doing.
7.hope it works.

Package Control no module named package_control.add_repository_channel_command

I've updated to the most recent version of Package Control for Sublimetext 3 via Git, but none of the commands work. The menu items are still present, strangely enough. When I open the log with Ctrl+`, I see this error:
ImportError: No module named 'Package Control.package_control.add_repository_channel_command'
How can I get it to work again?
Apparently the Package Control .sublime-package file is outdated, and in this case, referencing a python module that has been moved to a different python package (from package_control to package_control.commands).
This can be easily fixed by deleting Installed Packages/Package Control.sublime-package.
I use sublime text 3
From this site, I Follow these steps:
Go to http://wbond.net/sublime_packages/package_control/installation
& copy the long command there.
Open the Sublime Text 2 console by
pressing Ctrl+.
Paste the command you copied into the Sublime Text
console.
Press Enter.
After Package Control installs, restart
Sublime Text.
Then I got the error like that.
I have tried :
check ignored_packages on set but I found nothing.
Download package manager and copy it to Installed Packages, but not works.
Then I update my sublime to the newest version, then the error is gone.
That is my tips, you should try one of the steps, like what I have tried.

Resources