6

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?

1

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

11 Comments

I needed to install that since when I import it results in error - No module named tkinter
In that case, a common solution is to set the TCL_LIBRARY environment variable as described here. Are you on Ubuntu? Which version? Please add such information to your question.
have also tried import Tkinter but that didin't work either. Also tried TCL approach but I don't see any tcl library in my installations.
Which answer are you pointing to? None of them suggested to install tkinter the way OP asked, and my answer is correct @frank
I'm sorry; you're right. I didn't read the OP's question carefully, so I missed "don't have sudo access." If you accept my edit, I will upvote your answer instead of downvoting
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.