Python Turtle Graphics window shows nothing - python

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.

Related

Python cant recognize my installed modules [duplicate]

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...

Python turtle.Screen() not working properly on new Mac. Google has failed me

I recently got a new computer (Mac 14" Monterey OS) and reinstalled Python, PyCharm, etc. Everything seems to work okay except when running turtle Screen(). The code finishes with exit code 0 (no errors) but when the launcher pops up its just a tiny black screen that flickers. Doesn't even display the title correctly anymore.
It seems I've tried everything: re-installing Python, installing a later version (Python 3.9 vs 3.10) and reinstalling PyCharm, making sure the interpreter is okay. Nothing is working. I've spent about 2 hours googling to find a solution. I'm stuck and frustrated since I am supposed to be doing a coding workthrough with a company this coming week.
Here is the code that should be running:
import turtle
screen = turtle.Screen()
screen.title("States Game")
image = "blank_states_img.gif"
screen.addshape(image)
turtle.shape(image)
def get_mouse_click_coor(x, y):
print(x, y)
turtle.onscreenclick(get_mouse_click_coor)
screen.exitonclick()
And here is an image of what is going on...
please click this link to see image
Check your python interpreter version.
I have the same issue when it uses python3.8, after upgrading to 3.9. It works perfectly.
You need to install Python yourself instead of relying on the Python provided by macOS. I downloaded latest macOS 64-bit universal2 installer from https://www.python.org/downloads/macos/ and it works. (make sure you create new interpreter in Pycharm, using the newly installed python)
I think the cause of the issue is that the tkinter package has issues for the builtin python.

Import "matplotlib" could not be resolved from source Pylance(reportMissingModuleSource)

whenever I try to import matplotlib or matplotlib.pyplot in VS Code I get the error in the title:
Import "matplotlib" could not be resolved from source Pylance(reportMissingModuleSource)
or
Import "matplotlib.pyplot" could not be resolved from source Pylance(reportMissingModuleSource)
The hyperlink of the reportMissingModuleSource sends me to https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules, where it says:
"Diagnostics for imports that have no corresponding source file. This happens when a type stub is found, but the module source file was not found, indicating that the code may fail at runtime when using this execution environment. Type checking will be done using the type stub."
However, from the explanation I don't understand exactly what's wrong and what I should do to fix this, can someone help me with this?
I can reproduce your question when I select a python interpreter where doesn't exist matplotlib:
So, the solution is opening an integrated Terminal then run pip install matplotlib. After it's installed successfully, please reload window, then the warning should go away.
Just changes the interpreter to 2.7.x in left-bottom corner enter image description here
I experienced a similar issue even after installing vs_BuildTools.
Matplotlib could not be resolved from source parlance
What to do:
open the Command Palette (Ctrl+Shift+P)
Type: Python: Select interpreter Here is the interpreter that worked for me!
Navigate to your project.
Select the latest interpreter or check what interpreter
I had the same issue. Sometimes it's back to multiple versions of python on your device. You just need to change the path. Make sure the correct Python interpreter is selected in your IDE.
In vscode Press CTRL + Shift + P or (⌘ + Shift + P on macOS) to open the command palette. Then type Python select interpreter in the search field and choose the right version.
I have the same issue - I did two things and its working now
Check if there is some earlier versions of python installed on your machine - if yes then remove and reinstall the latest one
Second install the Microsoft C++ Build Tools
https://visualstudio.microsoft.com/visual-cpp-build-tools/
Restart the app and run again.
I was getting the same problem and realised the package install path for my active virtual env wasn't listed in sys.path
after appending this location to sys.path my .ipynb was able to import matplotlib

VSCode: Using the MS Python extension cannot execute code

I have been using VSCode with the Microsoft Python extension for a couple of months now. However just today I found that the green button I had in the top right that executed my code is gone. I have tried uninstalling the python extension and reinstalling, I have deleted and redownloaded VSCode, I have tried installing code runner. None of these have fixed the issue.
This is the image of my VSCode, which may help to solve the issue:
When I tried to select the Python: select interpreter I got an error in the bottom right that says,
"Command 'Python: Select Interpreter' resulted in an error (command 'python.setInterpreter' not found)"
I have never experienced an issue like this before so any help is greatly appreciated. Thank you!
Image of the plugin I have installed.
Try the following. If that does not help create a new bug.
Do the following to remove stale versions of the extension:
1.Uninstall Python extension (if you have pylance uninstall it first) in visual studio code.
2.Close all instances of VS Code or close visual studio code.
3.Go to, %USERPROFILE%/.vscode/extensions (on windows) or ~/.vscode/extensions on Windows/Linux/Mac.
4.Go to Run and give %USERPROFILE%/.vscode/extensions (on windows). It will open extensions folder.
5.Delete any folder with the name starting with ms-python.python*
6.Start VS Code, and install Python extension again(also pylance if you uninstalled it in step 1).
So I had faced the problem and couldn't find solution until I stared at VS code and found at the bottom left corner that it was in restricted mode, you have to run it in trust mode and it will fix the problem.
If the option is not coming, there is an option to run the program on the left panel in vs code which looks something like this:
Then you need to click debug and run or whatever the option is, if that is blurred out then you've not saved the file, first save it and then again do the same options, and then it will run.
I figured it out!!! The most recent update for the Microsoft Python plugin on VSCode seems to be bugged or something, I'm not sure. However I installed an older version and everything works now, including bringing back the green run button. Thank you all so much for the help!
Yep it's an issue with the most recent releases of vscode. The quick fix right now is just to roll back to an older version. You can easily do this by pressing CTRL+SHIFT+X in vscode to get to the extensions menu, and then clicking the Python extension, and then clicking the little arrow to the right of "uninstall". Here, you can just click "Install Another Version".
For me v2020.10.332292344 did the trick.
https://github.com/microsoft/vscode-python/issues/14959
Many others are facing the issue right now too.
https://github.com/microsoft/vscode-python/issues/14977
I am using WSL2, and i encountered this error today. My VScode used to work fine until my version was automatically upgraded to 1.60. When i checked my extensions, it said that my Python extension is not installed in WSL2, so i clicked on install and the problem was solved.
It may also come from the restricted mode. Please make sure you're in a trusted window.
"Command 'Python: Select Interpreter' resulted in an error (command 'python.setInterpreter' not found)"
The error happened on the newer version 3.10.6 I installed on my new system.
I uninstalled the new python version. Then went to Microsoft store and installed the older version 3.9 directly from the store. When I tried adding the interpreter again on vscode, it was successful.
reloading or upgrading python extension worked for me.
Kindly install the Python interpreter from the following site:
https://www.python.org/downloads/
Then vs code will ask for permission to run the interpreter.
and then its done

pygame import error in eclipse

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.

Categories