My Idle is throwing errors that and says tkinter can't be imported.
Is there a simple way to install tkinter via pip or easy_install?
There seem to be a lot of package names flying around for this...
This and other assorted variations with tkinter-pypy aren't working.
pip install python-tk
I'm on Windows with Python 2.7 and I don't have apt-get or other system package managers.
The Tkinter library is built-in with every Python installation. And since you are on Windows, I believe you installed Python through the binaries on their website?
If so, Then most probably you are typing the command wrong. It should be:
import Tkinter as tk
Note the capital T at the beginning of Tkinter.
For Python 3,
import tkinter as tk
If you are using virtualenv, it is fine to install tkinter using sudo apt-get install python-tk(python2), sudo apt-get install python3-tk(python3), and and it will work fine in the virtual environment
Well I can see two solutions here:
1) Follow the Docs-Tkinter install for Python (for Windows):
Tkinter (and, since Python 3.1, ttk) are included with all standard Python distributions. It is important that you use a version of Python supporting Tk 8.5 or greater, and ttk. We recommend installing the "ActivePython" distribution from ActiveState, which includes everything you'll need.
In your web browser, go to Activestate.com, and follow along the links to download the Community Edition of ActivePython for Windows. Make sure you're downloading a 3.1 or newer version, not a 2.x version.
Run the installer, and follow along. You'll end up with a fresh install of ActivePython, located in, e.g. C:\python32. From a Windows command prompt, or the Start Menu's "Run..." command, you should then be able to run a Python shell via:
% C:\python32\python
This should give you the Python command prompt. From the prompt, enter these two commands:
>>> import tkinter
>>> tkinter._test()
This should pop up a small window; the first line at the top of the window should say "This is Tcl/Tk version 8.5"; make sure it is not 8.4!
2) Uninstall 64-bit Python and install 32 bit Python.
When installing make sure that under Tcl/Tk you select Will be installed on hard drive. If it is installing with a cross at the left then Tkinter will not be installed.
The same goes for Python 3:
When you install python for Windows, use the standard option or install everything it asks. I got the error because I deselected tcl.
I came here looking for an answer to this same question and none of the answers above actually answer the question at all!
So after some investigation I found out:
there is a package (for python 3.x at least):
pip3 install pytk
The problem is, it is only the python part of the equation and doesn't install the tkinter libraries in your OS, so the answer is that you can't install it completely via pip
https://tkdocs.com/tutorial/install.html
Personally I find this very annoying as i'm packaging a python application to be installed via pip that uses tkinter and I was looking for a way to have pip ensure that tkinter is installed and the answer is I can't I have to instruct users to install it if it's not installed already, a very poor experience for end users who should not need to know or care what tkinter is to use my application.
Had the same problem in Linux. This solved it. (I'm on Debian 9 derived Bunsen Helium)
$ sudo apt-get install python3-tk
In python, Tkinter was a default package, you can repair the installation and select Tcl/Tk. When you run this, DDL should be installed like so:
I'm posting as the top answer requotes the documentation which I didn't find useful.
tkinter comes packaged with python install on windows IFF you select it during the install window.
The solution is to repair the installation (via uninstall GUI is fine), and select to install tk this time. You may need to point at or redownload the binary in this process. Downloading directly from activestate did not work for me.
This is a common problem people have on windows as it's easy to not want to install TCL/TK if you don't know what it is, but Matplotlib etc require it.
I was trying to upgrade my tkinter from the python built-in and found this method useful:
conda install -c anaconda tk
I had the similar problem with Win-8 and python-3.4 32 bit , I got it resolved by downloading same version from python.org .
Next step will be to hit the repair button and Install the Tk/tkinter Package or Just hit the repair.
Now should get Python34/Lib/tkinter Module present.
The import tkinter should work ..
Easiest way to do this:
cd C:\Users\%User%\AppData\Local\Programs\Python\Python37\Scripts>
pip install pythonds
Inside cmd, run command pip install tk and Tkinter should install.
if your using python 3.4.1 just write this line from tkinter import * this will put everything in the module into the default namespace of your program. in fact instead of referring to say a button like tkinter.Button you just type Button
Related
A Python embeddable package can install pip separately (pip with embedded python), but can it also install IDLE separately? As the embeddable package has pythonw.exe already, I tried to externally load idle.pyw with it, but more seem to be needed.
The IDLE IDE is part of the CPython standard library. It is usually an option packaged with tkinter, _tkinter, and, on Windows and Mac, an appropriate version of tcl/tk. Unless embedded Python comes with tkinter and _tkinter and tcl/tk is available, installing IDLE would be useless as well as difficult. It is not available as a separate package on pypi.org. (There are a couple of packages, such as https://pypi.org/project/friendly-idle/ that wrap or extend already installed IDLE.)
https://pypi.org/project/idle/ is a useless, non-functional, pretend package. "This is a program written in tkinter which acts as text editor.This can be used to edit file and as alternative of notepad." is a complete fiction. py -m pip install idle installs a 26-line idle.py. As reported in a comment, it tries to import a fictional module 'layout'. It later tries to run a fictional 'gui.mainloop()'.
The title of the question kind of says it all, but here goes.
I'm currently trying to install pyqt5 and pyqt5-tools on my system (not in venv). I have a Python 3.9 installation in C:\Program Files\Python39. Usually everything works fine in that, if i have admin privileges pip installs the package to the Python installation and if not it puts it into C:\users\username\appdata\roaming\python\python39. Now I have encountered something strange, even if I have admin privileges and try to install pyqt5 it decides to put it into the AppData Python directory instead of the actual python install inside C:\ProgramFiles\Python39.
I know that I could probably fix this by using -t, but I am curious as to why it would be this way. Why only PyQt5? Every other package worked absolutely fine until now. I've tried installing random other packages afterwards and they also worked fine. Even PyQt6 was completely normal. So what is it about PyQt5 that makes pip act in weird ways? After about 15 retries and permutations of the install I am still no closer to an answer.
I'm grateful for any explanation at this point, so thank you in advance!
I was trying to install PyQt 5.9 but I have no idea what I'm doing. According to what I've seen I have to download Qt from:
https://qt-project.org
and then SIP (whatever that is...) and PyQt from:
http://www.riverbankcomputing.com
I did all that and Qt weights like 30 Gb...
Now I have to install pyqt but the README.md file says this:
'''INSTALLATION
Check for any other README files in this directory that relate to your
particular platform. Feel free to contribute a README for your platform or to
provide updates to any existing documentation.
The first step is to configure PyQt5 by running the following command.
python configure.py
'''
And I have no idea what to do now, I keep getting the 'no such file/directory found' error.
I went to the directory where I have python installed and I still get the same.
-
I have a Mac and python 3.6
Turns out I have Qt 5.8 already installed, and since I just downloaded 5.9 I'd like to upgrade it but I don't know how. And maybe it's taking up another 30Gb somewhere else.
Also, when I type 'which python' I get 'anaconda/bin/python' and not python 2.7, how do I fix that? also I went to the dir where I have python and have python 2.4, 2.5 and 2.7. Should I just delete the others? and what is SIP??
Check these steps
Go to the QT website and download it.
Install python on your pc,
If it's Linux: sudo apt-get install python3.6
Or see this link.
Install also some IDLE to work on, I'd recommend you to use PyCharm
You can install now your PyQt through your Pycharm, see in here, find for pyqt5.
There is always the option to install through pip3, try to use pip3 instead of pip, since you are using python3.
After having pip3, try now to install your pyqt5. Check it out.
Now you have an IDLE to work on with PyQt and Qt in your machine, maybe you have to say in your PyCharm that you will use python3.6 as your interpreter.
I have been using PyCharm on Ubuntu to run some Python code, where in Edit Configurations I specified the interpreter path as /usr/bin/python2.7. The code uses the pygame module, and so to install this, I also ran sudo pip install pygame. Then I used import pygame in my Python script, and the file ran ok.
However, I now want to use Python 3.4. So, in PyCharm, I specified the interpreter path to be /usr/bin/python3.4. However, when I run the same file, I now get the error: ImportError: No module named 'pygame'.
Can somebody explain why this is happening? How can I get my Python 3.4 interpreter to find Pygame?
Thanks!
Each python installation has a separate set of libraries. Your python 3 does not know about Python 2 and its libraries. It seems the default pip command calls the python2 pip script. Run again the pip install, but with the python3 pip (look for it in your python3 folder, it is probably named pip3)
As others have pointed out, different Python installations will maintain their own independent set of libraries. Bear in mind that you can install packages from the same window that you use to change the interpreter in PyCharm for a project. You might find that more convenient if you're switching between interpreters.
You just click the green 'plus' icon to do so:
pygame has different releases for each version of Python.
As you have the Python 2.7 module and want to upgrade to Python 3.4, you'll need to reinstall pygame using Python 3.4 instead, you can using pip again or you can download files from here: http://www.pygame.org/download.shtml.
I, as it will soon be obvious, am a total newb when it comes to Python.
I am running python version 3.5 on Windows 10, 64 bit.
I installed the PyAutoGui module for a small project I am working on. At first, everything worked perfectly. But now it appears that PyAutoGui is crashing when it clicks. I suspect that it's because PyAutoGui is only intended for use up to Python 3.4.
In order to rectify this, I downloaded Python 3.4. Unfortunately, however, when I try to install PyAutoGui (using pip install pyautogui), it tells me that it's already been installed because it sees it in the Python 3.5 folder.
My question is this: How do I install PyAutoGui in Python 3.4 with it already installed in Python 3.5?
Assume that I know virtually nothing about how to install a module manually without using pip
Thanks in advance!
If you have multiple versions of Python installed you need to find your versions and rename them and their Pips.
In windows the path is, C:\\Users\USERNAME\AppData\Local\Programs\Python\Python3x-32. The x should be replaced with the Python version and USERNAME with your username. On Mac it's located in /usr/local/bin/python. On Linux it should be in /usr/bin/python. The location might vary depending on OS and Python version.
Rename the files python.exe/python and pip.exe/pip so that each file is different. I named mine python35.exe, python2.exe and python.exe(for 3.5, 2.7 and 3.6).
Now when you execute your pip command use, pip34 install pyautogui or whatever you named the file.
Or if you really want to you can go the painful way of renaming all the path variables, but I won't explain that here.