Think Python - Can't get tkinter to work - python

I am all new to everything about coding and programming, and I'm right now reading the book Think Python. Now I have to make tkinter work, so I can import the module TurtleWorld. First I try to import tkinter just to see that it work, and it does. Then when I'm trying to import TurtleWorld, suddenly there is no module called tkinter? I have no idea what to do, feels like I have been doing everything I could find! I'm using python 3.4.1 and I haven't downloading tcl or swampy cause they already came with python.
>>> import tkinter
>>> import swampy.TurtleWorld
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import swampy.TurtleWorld
File "C:\Python34\lib\site-packages\swampy\TurtleWorld.py", line 8, in <module>
from Tkinter import TOP, BOTTOM, LEFT, RIGHT, END, LAST, NONE, SUNKEN
ImportError: No module named 'Tkinter'

You are using Python 3.4.1 and according to the Swampy: Installation Instructions you need to have Python 2 installed to use the Tkinter module. Python 2 is the version of Python used in Think Python, and you will not be able to use Swampy with Python 3. The current version of Python 2 is in the Python 2.7 series.
To see if you have the Tkinter module, at the Python prompt, type:
import Tkinter
Note that the word Tkinter is case sensitive and the tkinter module (not the Tkinter module) should be used with Python 3.

Related

Python module, pyttsx3 not recognised in VS code or pycharm

I am trying to make a bot that responds to certain question asked like ‘what is the time’ . I am trying to use pyttsx3 module to make it work but this error is coming:
Traceback (most recent call last):
File "/Users/HarAd MAC/Desktop/Projects/Python_Work/bot.py", line 1, in <module>
import pyttsx
ImportError: No module named pyttsx3
I have download the module and checked it in VS code Terminal. It is also showing Requirement already satisfied. Can someone help me in this problem. Same error was shown when I was trying to run it in pycharm. These type of problems have also occurred when using modules that have to be download manually.
I am using MacBook Air big Sur and python 3.9.
Thanks.
I don't know for sure but I believe when your import the library you have to do import pyttsx3 while what you were doing is import pyttsx. Here's some more info on usage and how to import

trying to convert this file to python 3 and getting the error module not found

I'm using the solitaire.py file and trying to convert it to Python 3. It was originally 2.7 and works fine in that version but need it in 3 so I can make an AI with PyTorch to play it but I'm having an issue where:
from Canvas import Rectangle, CanvasText, Group, Window
shows the error:
ModuleNotFoundError: No module named 'Canvas'
Does anyone have any idea as to why or if there is something similar I could use in python 3 to make it work?
Canvas was deprecated in Python 3.
Instead you can use tkinter by doing: [docs]
from tkinter import Canvas
Or do this:
from tkinter import *

ImportError; Issue installing Reportlab 3.4 with Python 3.5 in PyCharm

I am trying to run Reportlab 3.4 in Python 3.5 in PyCharm
I installed via Project Interpreter (and I also installed via Terminal). When I try to import the following packages
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.pagesizes import portrait
from reportlab.platypus import Image
I get the following error:
ImportError: No module named 'reportlab.pdfgen'; 'reportlab' is not a package
It seems that several people had this issue a few years back but I cannot find a recent example of this happening.
Any insight would be appreciated.
I had the same problem. The import statements worked if I typed them directly into the interpreter, but if I tried to execute my program from a file I got import errors stating: ImportError...'reportlab' is not a package. These import conflicts arise if you name your script reportlab.py, you just have to rename it to something else.

How do I import Tkinter? [duplicate]

This question already has answers here:
ImportError when importing Tkinter in Python [duplicate]
(3 answers)
Closed 6 years ago.
When I try to import tkinter, this is the message I get:
Traceback (most recent call last):
File "Num_inc_dec.py", line 1, in <module>
from Tkinter import *
ImportError: No module named Tkinter
I've searched for my error and have found nothing. I've tried just typing import Tkinter. I'm using python 2.7, but just in case I have also tried using a lower case t.
Additional:
I'm using cygwin to launch my .py files as I'm new to programming, and that was in the tutorial to setting up an environment to work in that I used. I suspect this is part if not the error as I can find nothing online fixing my problem.
Edit: I fixed it. When installing cygwin I had to enable something to get it to work. I searched tkinter and enabled it from the thing that came up.
"The Python Windows Installers include Tcl/Tk as well as Tkinter. These are essentially a one-click install of everything needed." http://tkinter.unpythonic.net/wiki/How_to_install_Tkinter
I would check that you are actually running the correct version of Python.
Perhaps try explicitly stating you would like to run 2.7 with
$python2.7
>>> import Tkinter
As
import Tkinter
will return an ImportError in python 3.5. But will execute correctly in 2.7.
Then if the problem has not been solved, just reinstall python 2 with the windows installer. Tk and Tkinter are packaged with the python installer.

Python: can not import util

While reading the code for django/forms/widgets.py, I saw:
from util import flatatt
To dig deeper, I tried to import the util module in a Python shell in my terminal, but I got an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named util
This left me confused. What is wrong?
Django is (ab?)using Python's import system in order to import something from django.forms.util. Import that module instead.
In python, you get this ImportError:
Traceback (most recent call last):
File "b.py", line 3, in <module>
from util import flatatt
ImportError: No module named util
Some programmer out there created a library for your python script to use. Your program was unable to find that library. So the interpreter tells you that it can't be found. You have a few options. Either you have to define the library and functionality yourself, or you'll have to review the instructions and source code of the program you are trying to run, and try to figure out what is broken to prevent the library from being included. Or the final option is to remove any usage of that library in the current script.
You can define the module yourself like this:
Put this in util.py in the same directory as your widgets.py file.
def flatatt(prompt):
print("ok")
If you define that, you will get a different error, the script will import your library, and find that method, but then will do the wrong thing, because the programmer who designed that code probably had some other functionality in mind.
You need to figure out what you did wrong, or what the original programmer did wrong, or how your specific system is different to cause this to work.
You can learn more about what I've described above here, by rolling your own python modules: Python: How to import other Python files
Often times these sorts of bugs are barriers to entry, the original developers don't want programmers who don't know the difference between an integer and a module using the software. So little problems like this are added, to help encourage you that you need to develop a better understanding of the source code under the hood. It's like a mechanic helping everyone become better mechanics by swapping the wires on the distributor cap. It isn't going to work until you swap them back rightly.
from django.forms.utils import flatatt
It worked with django 1.11 version, and may work with 1.8 through 1.10

Categories