Python module turtle not importing correctly - python

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

Related

AttributeError: module 'dbus' has no attribute 'lowlevel'

Error Message:
Traceback (most recent call last):
File "/home/upboard/visioonbot/Connect4Py/connect4.py", line 7, in <module>
import dbus
File "/home/upboard/visioonbot/Connect4Py/venv/lib/python3.6/site-packages/dbus/__init__.py", line 77, in <module>
import dbus.types as types
File "/home/upboard/visioonbot/Connect4Py/venv/lib/python3.6/site-packages/dbus/types.py", line 6, in <module>
from _dbus_bindings import (
File "/home/upboard/visioonbot/Connect4Py/venv/lib/python3.6/site-packages/_dbus_bindings/__init__.py", line 13, in <module>
import dbus.lowlevel as __dbus_lowlevel
File "/home/upboard/visioonbot/Connect4Py/venv/lib/python3.6/site-packages/dbus/lowlevel.py", line 32, in <module>
from _dbus_bindings import (
File "/home/upboard/visioonbot/Connect4Py/venv/lib/python3.6/site-packages/_dbus_bindings/ErrorMessage.py", line 13, in <module>
import dbus.lowlevel as __dbus_lowlevel
AttributeError: module 'dbus' has no attribute 'lowlevel'
Process finished with exit code 1
Here are the dbus files mentioned in the error path:
and the dbus_bindings files:
What is missing? How to solve this issue?
I've already reinstalled the packages using
sudo apt install python3-dbus
and
sudo apt-get install -y python-dbus
It looks like your issue might be that you are using a venv. python3-dbus does not play nicely with venv's.
You can try using --system-site-packages as suggested in https://stackoverflow.com/a/13367493/7721752.
Or use pydbus and vext.gi

Failed to import a module

I try to use ImageGrab (open-cv function)
OS: lubuntu
First, I did: sudo apt-get install python-opencv.
Installation went successfuly.
Then I tried to do: from PIL import ImageGrab. But at this point I got the following ImportError:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/user/lib/python2.7/dist-packages/PIL/ImageGrab.py", line 26, in <module> import _grabscreen
ImportError: No module named _grabscreen
Where am I wrong?
Unfortunately - ImageGrab only works with Windows
Alternative: pyscreenshot

Python + RaspberryPI can't import GPIO after installing: ImportError: No module named _GPIO

I have a RPi 2 (running raspbian jessie with pixel) and just tried to install the GPIO module:
I have downloaded and installed from source. Then I issue commands:
pi#raspberry:python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
ImportError: No module named _GPIO
so then I tried using sudo:
pi#raspberry:sudo python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
ImportError: No module named _GPIO
Then I removed the module from python, and installed it again using pip:
pi#raspberry:sudo pip install RPi.GPIO
pi#raspberry:sudo python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
ImportError: No module named _GPIO
Then I removed the module from python, and installed it again using apt-get:
pi#raspberry:sudo apt-get update
pi#raspberry:sudo apt-get -y install python-rpi.gpio
pi#raspberry:sudo python
>>> import RPi.GPIO as GPIO
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
ImportError: No module named _GPIO
It seems it has nothing to do with the install method, so I'm assuming it's something to do with either Raspbian Jessie + pixel or the current version of python-gpio is broken/incompatible.
Its strange because I am not importing "_GPIO", I am importing "GPIO", which indicates to me that my python syntax is not the culprit.
Could somebody please recommend what I should try next?
Also I searched this exact error on Google and got 1 result which was not helpful.
Thanks,
i think you have a dir called RPi in your current dir,so change your python file to another dir which doesn't have ,it works for me...hope it's helpful :)

Turtle won't import on python3.5 fedora 23

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

ImportError: cannot import name ResourceError

I'm trying to install couchdb app on debian using the following command
couchapp push http://user:pass#localhost:5984/acra-appname
and I'm having the following error output:
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/restkit/__init__.py", line 9, in <module>
from restkit.conn import Connection
File "/usr/local/lib/python2.6/dist-packages/restkit/conn.py", line 14, in <module>
from socketpool import Connector
ImportError: No module named socketpool
Traceback (most recent call last):
File "/usr/local/bin/couchapp", line 7, in <module>
from couchapp.dispatch import run
File "/usr/local/lib/python2.6/dist-packages/couchapp/dispatch.py", line 10, in <module>
import couchapp.commands as commands
File "/usr/local/lib/python2.6/dist-packages/couchapp/commands.py", line 15, in <module>
from couchapp import clone_app
File "/usr/local/lib/python2.6/dist-packages/couchapp/clone_app.py", line 15, in <module>
from couchapp.errors import AppError
File "/usr/local/lib/python2.6/dist-packages/couchapp/errors.py", line 7, in <module>
from restkit import ResourceError
ImportError: cannot import name ResourceError
As far as I understand the error is:
ImportError: No module named socketpool
How can I install this module or how to resolve the problem?
As Ifthikhan sugessted: Install it using a package manager such as apt-get and thereafter using pip you can install socketpool.
I had this problem when installing couchapp. I used pip to install it, and I thought it completed, but when I ran it I had the ImportError problem. Turns out the pip install didn't succeed and I first needed to:
apt-get install python-dev
Then when I did a
pip install couchapp
all of the dependencies were installed and couchapp ran without a problem.

Categories

Resources