when I import pygame using eclipse on my mac, there's a import error:
However, I can still run this program correctly, So what can I do to fix it?
to quick fix you can do:
PyDev Package Explorer>right click your project>properties>PyDev - PYTHONPATH>External Libraries>Add source folder>PythonX.X(version where you installed pygame)/Lib/site-packages/pygame
this will include one external library for this project, but you should check if you are working with the right python version you installed.
I have 3 versions of python, pygame is only on Python2.6, so all my new projects that use pygame must have python2.6 syntax and interpreter python26.
To check your interpreter settings:
Window(menu)>Preferences>PyDev>Interpreter - Python>New>interpreter name you can put anything you may remember, interpreter executable find the python.exe and put the path there, OK.
Now you have added the entry for the interpreter, if you look down in the same window, into Libraries you can add many packages you want the interpreter to look for to resolve names and syntax.
They make Pygame for every version of Python. I have it for Python 3.4 it came out in March 2014. If you are getting the error there is no module named Pygame. It is because Pygame is not in Python's path or you have the wrong version of Pygame for your current version of Python. You can find more Pygame downloads here that arnt on pygame.org. Click on the blue word Pygame at the top and it will take you to the proper section of the page.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Download the one you need for your Python version. If you hold the mouse over it it should show more info about the version in a tiny pop up. I am on windows but it found the path by itself. I'm not sure if it will for mac.
Related
I currently have Python 3.10.5 and pygame 2.1.2.
VScode 1.70.2
Versions
For some reason there is the following warning: Image for warning
Import "pygame" could not be resolved PylancereportMissingImports
Even though I have the pygame library installed using "pip install pygame".
And when I run the file by pressing the "Run Python File" in the right top corner, it runs perfectly without an error. It even uses the terminal to show whatever I am printing.
My issue here is the warning and that intellisense for pygame isn't working.
What can I do to fix that.
I already tried to make a clean install on everything, python, pygame, even VScode. Nothing.
Try to reload vscode (by command pallete or just restart the app), reinstall pygame and make sure python path is selected. Also it is worth to trying selecting interpreter. Open command pallete and type: Python: Select Interpreter, then select your python version.
yes as the #NoBlockhit stated probably you have 2 different python versions installed and vs code choses the one without the pygame library (https://code.visualstudio.com/docs/python/environments) if you scrolldown it shows you how to chose an in interpreter...
I think my code is nothing wrong. Because it's very simple, it worked very well on my Windows PC, and shows no error message at all.
from turtle import Turtle, Screen
turtle = Turtle()
screen = Screen()
screen.exitonclick()
However, on Pycharm on my Monterey M1 Macbook, the Python Turtle Graphics window shows nothing but black screen and scroll bars.
I think the application called python.app is something wrong. That's why I updated python with brew and re-installed Pycharm, but nothing has changed.
Does anyone know how to fix this?
Thank you.
have you tried to install the latest version of python? cause I'm facing the same problem earlier. I tried to install the latest python version and it just works like a charm now.
change the interpretepycharm interpreterr to 3.9 or 3.10 in pycharm.
Updating the interpreter will help fix the issue as it did in my M1 Mac and without needing to make a new project. However, there are a few extra steps needed to make sure it's compatible with your M1 chip.
Quick Steps:
Download the latest Python version (Make sure the download link is labeled as "macOS 64-bit universal2 installer" as it'll be fully compatible with your M1 Mac)
After installing the interpreter, open Pycharm -> Preferences -> Project: [Your Poject's Name] -> Python Interpreter
Click the Options button (Gear Button) next to the Python Interpreter Box and select "Add..."
Make sure "New Environment" is selected
Select any empty folder (or make one) to store your interpreter (I chose to store it in Documents in the "Personal Python Interp" folder)
For "Base Interpreter: ", "select the button with the three dots and paste /Applications/Python 3.10/IDLE.app/Contents/MacOS/Python, then press "OK" (IMPORTANT: Your Python version number may be different so update the "Python 3.10" to the python folder name found in "Applications")
Check both boxes for "Inherit global site-packages" and "Make available to all projects" (UNLESS you have specific interpreters for other projects)
If any, re-download any Python Packages you may need onto this interpreter
The turtle screen should be now fixed! I hope this helped!
I don't think it has anything to do with the M1 processor.
I have an M1 processor and had the same problem.
My solution:
Create a new project in Python.
Previously configured interpreter
Select Python 3.10 (the latest installed version).
Click the button with the three dots ...
Go to the directory of Python 3.10 (current version).
IDLE.app -> Contents -> MacOS and -> Select Python.
For me it looks like this:
/Applications/Python 3.10/IDLE.app/Contents/MacOS/Python
Then it works for me.
I just downloaded Pycharm because Spyder on Anaconda wasn't working anymore on my Mac. I am trying use Tkinter and have tried to run code using both
from tkinter import *
and
import tkinter as tk
The second is from my python class. Both times it returns
ImportError: No module named tkinter
I have tried to search for "tkinter" on Python Interpreter but there's no solid "tkinter." Only others like tkinter.math. Please help.
Tkinter would not be visible on Python Interpreter since it is a part of standard Python installation, the only additional modules or packages which user downloads are visible in Settings. Since, Spyder on your PC is not working as well, make sure python is installed properly and is configured correctly with path details properly set up.
I think you should check the interpreter of PyCharm.
Or Reinstall the python package and make a virtual environment.
the problem:
as part of my studies, i have tried to download PyGame for my own independent project. I've currently downloaded 1.9.6, as well as currently owning IDLE version 3.8. i have imported it many times:
folder.
on one occasion , i placed it in its own separate folder with the coding file in another internal folder
when importing it into a new python script, the result was that there was "no module named Pygame", even though it was in a file containing the recent edition (this method was used successfully to download Tkinter).
I also tried making a python script outside the contained folder like this
this,too had the same result.
Any idea what exactly to do?
any more important information
The computer type is a MAC 10.13.6 and the IDE is IDLE. As previously mentioned, the downloaded version is version 1.9.6 and i have not a clue what how many bits my computer manages. Apologies that this is probably one of MILLIONS of the exact same question answered.I've tried at least 2 of these solutions.
First you need to make sure that you have pip installed. Type pip in your cmd (command prompt) and if you get no errors you are fine. If you have errors follow this link to get it. If you are stuck on that link - basically all you need to do is uninstall python and then when you are installing it again tick the box that says:
Add Python 3.5 to PATH
Now just finish installing python.
Next you need to install pygame with pip install pygame in your cmd - run it as administrator just to be safe. If you receive errors try updating pip with python -m pip install --upgrade pip. Now create and save a new python file. Import pygame in that file by using the code import pygame. The output should be:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Now you are free to code in pygame! I hope this helped.
I am using Linux Mint 17 (Ubuntu 14.04) and already got pygame 1.9.2 working in Eclipse on my Windows PC. Now I also installed it on this machine, but it doesn't work. Thus there is no apt-get for python3-pygame I downloaded the source from https://bitbucket.org/pygame/pygame and built and installed it without getting errors.
When running the following on the command line I receive no error:
import pygame
pygame.init()
If I try the same in an Eclipse PyDev project I get the error: "Undefined variable from import: init".
First I thought that my Interpreter was not set up correctly, but the path where pygame is installed is added to the libraries (/usr/local/lib/python3.4/dist-packages). I realized that for Python2.7 pygame is installed in /usr/lib/pytho2.7/dist-packages instead, but this directory doesn't exist for python3.4 on my machine.
Since it seems to work on the command-line it must have something to do with the Eclipse or Pydev settings, right?
UPDATE:
Ok, now things are getting really confusing. I found out that pygame indeed is also working from within eclipse if I run the project, but only giving me these error messages for eg. pygame.init(), pygame.QUIT, pygame.K_ESCAPE, pygame.KEYDOWN. I find it very strange, because pygame.time.Clock() or pygame.display.set_caption() don't give error messages. So I only get undefined variable from import errors (also see here How do I fix PyDev "Undefined variable from import" errors? ).
Use sudo pip3 install pygame, pip3 should work assuming you have python3 and setuptools installed.
You can install pip3 using sudo apt-get install python3-pip and then use sudo pip3 install package_name to get whatever you want.
The only thing which worked for me (I spent two days now finding out what the problem is) is to add "pygame" to the forced builtins for the Interpreter (Window -> Preferences -> PyDev -> Interpreter -> Python Interpreter -> Forced Builtins Tab -> New -> pygame.
This is only a workaround, but at least I am rid of those errors for now and auto-completion still works. I didn't find any other solution that worked for me so far.
For me the problem was resolved by importing *.
instead of:
import pygame
try this:
from pygame import *
now instead of calling init() by saying pygame.init() just use init()
also you should not have to explicitly call using pygame. for the most part.
NOTE: after playing around with this in Eclipse I did end up having to use both:
import pygame
from pygame import *
for whatever reason one of my functions only works if I have pygame.even.get()
but the test of my code does not need to use pygame.
(I am sure there is a perfectly good reason but I am still very new to python)