No Module Named Pygame Sublime Text, Python3 - python

I keep getting an error while trying to import Pygame and Tkinter in Sublime Text.
When I look it up on Terminal it says bother are installed.
Thanks.

MACOS SOLUTION:
on the terminal type:
curl https://bootstrap.pypa.io/get-pip.py > get-pip.py (hit enter)
after installation type:
sudo pip install pygame (hit enter, enter your password and then hit enter again)
This should suffice it.
See, the way IDEs work on computers is they have their own environment integrated and the directory which the IDE is using might not be the same as the one your terminal is pointing to. By doing it this way the older versions/folders are overwritten and if there is none this installation process makes sure it's placed in an environment that is visible to most IDEs. I learned it after installing the Thonny IDE. But later on, I switched to Sublime. The only problem is the Pygame module given the fact the Tkinter is a totally integrated pre-installed library of the Python language.

Related

unable to download pygame module in python

I am a beginner in python , I want to download a module named pygame , I was told to type pip install pygame in the command prompt , I did it , now when I went back to vscode , and run "import pygame" , It says No module named 'pygame'
Things you should check :
In terminal (cmd), type pip list and check if pygame appears in the list
In terminal (cmd), if you type python, which version of python shows up ?
Check your system path to see where your default python is store on your computer
On vscode check if you are using the right python interpreter. Go to vscode do ctrl + shift + p. A search window will appear, type python interpreter. You should see an option name Python: Select Interpreter, click on it and if you see multiple python interpreter here you can just try them and see if it solve the problem.
You can try to replace pip with pip3 in all your pip commands and see if it works but sooner or later you will need to take a deeper look on how everything is set up on your computer, this will prevent you some headache along your developer journey
If you are lost and nothing works, I would simply suggest uninstalling python all together, make sure you've uninstall every instance of python on your computer and reinstall it from scratch. Make sure you check "Add to PATH" while installing
You can also look at virtual environement but if you are just starting out with coding and everything related to that, it might be a little too advance especially on windows (if you happen to be on linux this might be a solution it's really easy to set up on linux)

I tried to add Python to VSCode, but it won't work

I opened command prompt (I'm on Windows) and I typed:
'''none
pip3 install discord
'''
Then it said it installed discord, and I was ready to go! (I already had Python 3.9.7 installed)
Then when I opened VSCode up and typed: import discord I got this error message:
"discord" is not accessedPylance
Import "discord" could not be resolvedPylancereportMissingImports
What does this mean, and how can I fix it? I was really looking forward to coding the bot, but don't know how, now that this is messed up.
check in the bottom left corner of the VS Code window for which version of Python is it using. This issue usually occurs for me when I’m working in a virtual environment but VS Code is pointing to my global Python installation.
You can change the Python Interpreter in VSCODE to solve this issue.
Open settings in VSCODE by pressing Ctrl + Shift + P. Make sure your .py file is open while doing this step.
Search there Python: Select Interpreter and choose the right version.
Reload VSCODE and see if it works!
Open an integrated Terminal in VS Code,
run python --version, it should be python3.9.7 which is selected as python interpreter and shown in status bar.
run pip show discord to check if its location is \..\python3.9.3\lib\site-packages. If not, reinstall it.

Code is working in pyCharm but not in Visual Studio Code

I'm pretty noob to coding. I have been coding for about 3 months.
I made a program that could automatically enter Zoom class meetings for me. I'm using Pyautogui and Tkinter.
When I run my code in pyCharm, it works properly. The mouse moves automatically and enters the meeting perfectly.
I have tried running the same code in VSCode but it just opens the Zoom application. The mouse doesn't move and it doesn't type the meeting's ID.
I'm trying to use VSCode, because I'm trying to learn new languages and start creating different projects.
This is my code for entering the meeting.
def math():
subprocess.call([ "/usr/bin/open", "/Applications/zoom.us.app" ])
time.sleep(2)
join_meeting = pyautogui.locateCenterOnScreen('join.png')
pyautogui.moveTo(join_meeting)
pyautogui.click()
meeting_id = pyautogui.locateCenterOnScreen('meeting.png')
pyautogui.moveTo(meeting_id)
pyautogui.click()
pyautogui.write('...')
pyautogui.press('enter')
I use Tkinter to make it like some sort of application with buttons that each will take me to a different meeting. My code works properly but not when running it in VSCode, even though the Tkinter window still opens and opens the Zoom application, but doesn't type nor it moves the mouse.
Update: I found I have this version of pip installed in an old version of python interpreter. How can I change this?
I'm pretty new so I'm probably making a really easy mistake. Would really appreciate it if you could help. :)
This most likely is because you have not installed the Pyautogui Module. So, basically, PyCharm was meant only for Python (now supports more languages), so it made sure to install ALL the main packages. However, the Visual Studio Code was not really meant for Python. Therefore, the Visual Studio Code did not install the packages for you. It is simple to get it anyway. If you don't have pip, then you can search "How to install pip." If you have, then do:
pip3 install pyautogui
or
pip install pyautogui
You could refer to the following methods to check the installation of the module:
The source of pip is consistent with the environment currently selected by VSCode (shown in the lower left corner of VSCode), and the installed package can be used.
Please use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, it will automatically enter the VSCode environment you currently selected (the python interpreter displayed in the lower left corner of VSCode).
You could enter "pip --version" in the VSCode terminal to check the source of the installation tool pip, and the module will be installed here.
Check the installation package:
Reference: Environment in VSCode.
Update:
Please use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, it will automatically enter the currently selected VSCode environment, we can use "pip --version" to check the source of the installation tool, after confirming that they are consistent, use pip to install the module: (pip install pyautogui)

pycharm doesn't recognize pygame package

I'm using mac OsX 10.8.2, pyCharm 2.7.1. python 2.7.2
I want to use pygame package with pycharm. I followed the instructions on the pygame site and installed pygame 1.9.1 successfully.
When I write "import pygame" pycharm doesn't find the package.
I tried installing the latest updates of python, pycharm and pygame. I tried using the "install" window in the preferences. It installed "pygamess", "pygameui" and "pyviewx.pygame", but when I try to instal "pygame_loaders" it writes "Install packages failed: Error occurred when installing package pygame_loaders".
If you can please give simple instruction since I'm not a heavy mac-user.
To use pygame under OS X, you need to run Python under the 32 bit interpreter. It's usually called something like 'python2.7-32', and if installed from the package on http://www.python.org/, within /usr/local/bin
To get this working in PyCharm, open a project, then preferences ('apple'-'comma'), go to 'python interpreters', and click the '+' button in the right hand pane.
A list should appear and you'll see '/usr/local/bin/python2.7-32', select that and then make it the default for your PyGame project.
If you haven't installed Python from python.org, I recommend you do so; the current version is 2.7.3.
The above setup is how I got PyGame working in PyCharm on Sunday, so it should still be valid.
If you have a 2.7 virtualenvs running inside pyCharm you can manual install pygame.
Navigate to the virtual env on you disk via the terminal:
cd ~/.virtualenvs/Pygame
Or whatever directory you have. Now we active the virtualenv, just like we normal do when we not work inside pyCharm.
source ./bin/acivate
You should see something like this
(Pygame)mbp-2:Pygame pietje$
Now we can install pygame inside this env.
pip install hg+http://bitbucket.org/pygame/pygame
That's it and everything should work fine inside PyCharm. It does work on my machine :)

How do you import pygame libraries into Eclipse's pydev?

I have Eclipse working and am working uder the Pydev plugin, and I need some help with pygame. I'm on a mac and have managed to get pygame working for python 3.3 using homebrew, and pydev's causing me some trouble. The libraries don't seem to be recognized. I can use pygame as needed, doing things like
import pygame
and
pygame.init()
without problem, but Eclipse doesn't recognize the modules and says things like
unresolved import: pygame
Again, I think the issue here is Eclipse not having access to the pygame libraries. How do I fix this?
Windows > Preferences > pydev
look for the python interpreter line
on the libraries tab, click new folder and add the pygame folder path, apply and you're done
NOTE : make sure to use python 3.x as the project interpreter
I wasted forever trying to get this to work as well. I eventually found these steps (you don't need them all, just part of my struggles are shared here).
in Python Shell:
import sys
print (sys.path)
I noticed that no PYGAME appeared in path. Eventually I GAVE UP on the .exe binaries and was told to use .WHL files and Python PIP to install. But was told NOT VALID wheel file.
What EVENTUALLY WORKED was (in windows, but similar should work in other OS's) to run Command Prompt as Administrator (just to be sure). Maybe the solution will also work in other OS's (you'd have to try).
From C:\> I Changed Dir to my Python.exe (or the python program itself).
From my python directory in command prompt I typed the following (Like I would in a linux apt-get install command):
python.exe -m pip install pygame
Shortly after, ther ewere hash marks ##### indicating a download was taking place (linux type progress bar in shell).
In ECLIPSE without ever changing the Libraries folder to include PyGame folders I was able to run a sample Python PYGAME script sample (I got a white screen but haven't gone further yet). I was just happy to not have to see the trace back error message.
Just thought this would help someone.
python.exe -m pip install pygame [Worked perfectly]

Categories