Turtle won't import on python3.5 fedora 23 - python

I installed the tkinter packages from the fedora repo, then I ran a simple turtle code in python... A test one form a website. (with import turtle at the top)
I then tried running the following code:
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
And it got the following error
[max#localhost python]$ python3 test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import turtle
ImportError: No module named 'turtle'
And now even when I run the original program it no longer works.
It gives the exact same error as the test.py program.

dnf install python3-tkinter.x86_64

Related

Raspberry pi and Pygame Menu

I wanted to use a library in python called pygame-menu in raspberry pi because I wanted to develop a game with somebody else. I tested one of their demos and I got the following error:
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
File "/home/pi/Pandemic/GameDev.py", line 2, in <module>
import pygame_menu
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/__init__.py", line 66, in <module>
import pygame_menu.themes
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 386, in <module>
THEME_DEFAULT = Theme()
File "/home/pi/.local/lib/python3.7/site-packages/pygame_menu/themes.py", line 198, in __init__
bool, pygame.vernum.major == 2) # type: bool
AttributeError: 'tuple' object has no attribute 'major'
Here is also my code:
import pygame
import pygame_menu
pygame.init()
surface = pygame.display.set_mode((600, 400))
def set_difficulty(value, difficulty):
# Do the job here !
pass
def start_the_game():
# Do the job here !
pass
menu = pygame_menu.Menu(300, 400, 'Welcome',
theme=pygame_menu.themes.THEME_SOLARIZED)
menu.add_text_input('Name :', default='John Doe')
menu.add_selector('Difficulty :', [('Hard', 1), ('Easy', 2)], onchange=set_difficulty)
menu.add_button('Play', start_the_game)
menu.add_button('Quit', pygame_menu.events.EXIT)
menu.mainloop(surface)
Can you please help me fix it I ran the program with Thonny
it seems that the error comes from the pygame_menu library. You should check the compatibility between pygame_menu and pygame version. The last version of pygame-menu require pygame 1.9.6 or more.
I have fixed it. It turns out the raspberry pi has a default version of 1.9.4 of pygame and pygame-menu required 1.9.6 and above so I upgraded it with this command:
python3 -m pip install -U pygame --user

Python module turtle not importing correctly

This is my first time using the turtle module in python but I can't seem to import it?
Here's my code:
import turtle
turtle.shape("turtle")
turtle.speed(1)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.exitonclick()
I run this as $ python3 example.py
And I get
$ python3 example.py
Traceback (most recent call last):
File "example.py", line 1, in <module>
from turtle import *
File "/usr/lib/python3.7/turtle.py", line 107, in <module>
import tkinter as TK
ModuleNotFoundError: No module named 'tkinter'
If I run Python2 python example.py
$ python example.py
Traceback (most recent call last):
File "example.py", line 1, in <module>
import turtle
File "/usr/lib/python2.7/lib-tk/turtle.py", line 107, in <module>
import Tkinter as TK
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 42, in <module>
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package
This is a simple one to solve:
sudo apt-get install python3-tk
One of the other commenters suggested python-tk which wouldn't work for you here.
It was
sudo apt install python3-tkinter

Missing OpenGL.GL model

I am trying to run this code:
import pygame
from pygame.locals import *
from OpenGL.GL import *
from OpenGL.GLU import *
But I get this error:
Traceback (most recent call last):
File "/Users/Abood/Documents/lol.py", line 3, in <module>
from OpenGL.GL import *
ModuleNotFoundError: No module named 'OpenGL.GL'
I tried removing the .GL part and this came up:
Traceback (most recent call last): File "/Users/Abood/Documents/lol.py", line 4, in <module> from OpenGL.GLU import * ModuleNotFoundError: No module named 'OpenGL.GLU'
You have to install both the pygame and OpenGL packages. The easiest way is using pip:
pip install pygame
pip install PyOpenGL
This worked for me. After installing the packages and running your code, I got:
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
There are also different ways to install the OpenGL module. See the installation instructions on the PyOpenGL website.

tkinter ImportError in Pycharm but works from shell Ubuntu Xenial

import sys
if sys.version_info[0] < 3:
import Tkinter as tk ## Python 2.x
print("Python 2.X")
else:
import tkinter as tk ## Python 3.x
print("Python 3.X")
print("version", tk.TclVersion)
If I run from shell with python I get:
$ python test_tk
Python 2.X
('version', 8.6)
If I run from shell with python3 I get:
$ python3 test_tk
Python 3.X
version 8.6
But in PyCharm I get ImportError
Traceback (most recent call last):
File "/home/myuser/PycharmProjects/Project/file.py", line 12, in <module>
import tkinter as tk
File "/usr/lib/python3.5/tkinter/__init__.py", line 35, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named '_tkinter'
Process finished with exit code 1
I looked in PyCharm File>Default Settings>Project Interpreter>+ and it doesnt find any tkinter module...
I tried changing environment and in python 2.x I get:
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
From all the articles I read my conclusion would be that this is a path issue.
How can I resolve this?

How to control UI using pyautogui

I have installed pyautogui in my PC. I my project i entered the code
import pyautogui
im1 = pyautogui.screenshot()
im1.save('my_screenshot.png')
im2 = pyautogui.screenshot('my_screenshot2.png')
It replies error message as shown below ...
Traceback (most recent call last):
File "C:/Users/rkl7cob/Desktop/autoGui.py", line 17, in <module>
import pyautogui ImportError: No module named pyautogui
That could happen because your PyAutoGui module isn't updated
pip install pyautogui --upgrade

Categories

Resources