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

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]

Related

in vscode, pygame wont import but it is installed and is working in the windows console ,and the python app thing

im very new to code in general so this could be a stupid beginner problem ive searched for things but i couldnt find something useful for me
under Problems is the message: Import "pygame" could not be resolved
You can use pip show pygame to view the package installed location.
And check whether the installation location is consistent with the version corresponding to the selected Python interpreter.
There are two ways to solve this problem:
"ctrl+shift+P" and change the python interpreter.
If you don't want to change the interpreter, you can use pip -t flodername pygame #flodername is your used python package location. Install the pygame package to the specified directory
First, try restarting your computer or vs code
Use this command in your vs code terminal if the above doesn't work:
pip uninstall pygame
Then reinstall pygame using:
pip install pygame
If this also does not work then follow these steps:
Go to the scripts folder of python.
Open command prompt or Powershell in the script folder.
Use this:
C:\python34\scripts> python -m pip install pygame
Done
As an Anaconda user, I found my packages were being installed to C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages, which Visual Studio Code was not picking up on.
With the Pylance extension installed, open Settings (File > Preferences > Settings, or Ctrl+,)
At the top, beside Workspace, choose User
Under Extensions > Pylance, scroll until you find Python › Analysis: Extra Paths and select Add item.
Type in the path to which packages are being stored (in this case, C:\Users\YOUR_USERNAME\anaconda3\Lib\site-packages)
Click OK and after a couple moments, you should see something like the below image (i.e, the path is included in the list of paths).
Finally, your Python file should have picked up on the changes, but if not, reload it or VS Code. If nothing else, add another path that packages are being saved to or change your Python Interpreter. Using another virtual environment's interpreter wouldn't be very helpful, after all.
I may be late, but I hope this helped.

why is pymunk not letting me import it and saying "no module named "_cffi_backend""

i am making a hard version of atari breakout
so when i import pymunk because I wanted to make the ball then it will say "no module named "_cffi_backend"
i have asked people on Youtube and reddit but nobody answered the questions
i have tried uninstalling cffi and pymunk, downgrading python and more
can anybody fix this problem
(and also i use microsoft visual studio 2019 and pyglet and python 3.9)
https://i.stack.imgur.com/sBY1O.png
Can it be because of something fishy with Visual Studio? Otherwise I cant think of much..
To validate if Pymunk can work on your computer you can try to install a fresh Python and Pymunk through conda, which will give you a completely separate installation of Python.
Download and install Miniforge: https://github.com/conda-forge/miniforge (If you get the option, dont set this new miniforge Python as your default Python)
Open the miniforge command line prompt and run conda install pymunk
When installed, run python -m pymunk.tests
Add the output here :)
Secondly, you can try to run your project from the command line instead of from within VS.
First you need to find out the folder where you have the files. In VS you can right-click on the file and use "Open Containing Folder" to go to the file in Explorer. You can also use "Copy full path" to copy the path.
Next, open the command prompt (or Windows Terminal in case you have it installed).
Navigate to the folder with the file. cd long-path-to-folder
Run the "main" file, I guess its atari.py in your case, but Im not really sure.

Python packaging tools not found problem in pycharm [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.

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)

No Module Named Pygame Sublime Text, Python3

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.

Categories