I am using a virtualenv on a Linux machine. I don' have sudo
access so I can use pip
only.
I tried:
pip install python-tk
But this resulted in this error message
Collecting python-tk
Could not find a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk
How can I install Tkinter in virtualenv on Linux?
You can't install tkinter using pip because tkinter is an interface to a C++ library called Tk, whereas pip is coded with Python.
Luckily you do not have to worry about the above statement because tkinter comes as a built-in library for the standard Python distribution.
So what you have to do is:
cd to_your_virtualenv_directory
source bin/activate
python
import tkinter as tk
Note:
Depending on your settings, maybe when you type python
you will notice you are prompted to work with Python 2.x instead. In that case, just type this: import Tkinter as Tk
. If, however, typing python
leads you to use Python 3.x (as I set it on my machine), but you prefer to work with Python 2.x then simply type python2
instead of python
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With