Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install Tkinter in virtualenv on Linux without Sudo access

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?

like image 997
garg10may Avatar asked Jul 24 '17 11:07

garg10may


Video Answer


1 Answers

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:

  1. Go to your virtualenv directory: cd to_your_virtualenv_directory
  2. Activate it: source bin/activate
  3. Access your python shell within it: python
  4. Then 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.

like image 179
Billal Begueradj Avatar answered Nov 15 '22 09:11

Billal Begueradj