Linux Mint 17 tkinter not installed - python

I was trying to run a program that I have been making and ran into a problem with tkinter not being installed, as when I try to run my script in pycharm I get this error: ImportError: No module named '_tkinter', pleaseinstall the python3-tk package`
So I searched on here and found a solution and entered these commands:
sudo apt-get install python-support
sudo update-python-modules -a
which didn't work so I tried:
sudo apt-get install python3-tk
which was tagged as the answer on this question but it threw this error at me:
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.
Being pretty new to linux and the terminal, I am completely clueless as to how to do this.
I am using python 3.5 and just want to install tkinter so I can run this script, also before anyone asks yes I have imported tkinter and not Tkinter.

sudo apt-get install python3-tk is the correct way to install tkinter for Python 3 on Linux. However, you interrupted apt while it was installing. To fix the errors, run the command the error message suggested and then install tkinter.
sudo dpkg --configure -a
sudo apt-get install python3-tk
Then you can add from tkinter import *, import tkinter as tk or import tkinter to the beginning of your program depending on how you want to use it. You may also be interested in installing idle-python3.4.
Next time you need to install something just open the software manager from Menu, search for the program and install it :-)

Well when all logic fails- panic. Look for the illogical. I found that I was not running Python 3. My text editor is Geany, and reverts everything to run its default, which was set at Python 2. That included #!.
So, change the defaults in Geany:
Build > Set build commands > then in the dialogs replace every instance of Python with Python3

Related

How do I run a Python script with sudo? (MAC)

I want to test the keyboard.on_press_key() function, but OSX blocks it naturally. When I try to run it through the terminal using sudo python [pathtofile] I get an import error: "ImportError: No module named keyboard". I tried installing the module using sudo (sudo pip install keyboard) but, even though it installs just fine, I still get the same error. 
What am I doing wrong?
Note that python on macOS refers to the system installation. You should not install packages via pip to the system installation of Python. I'd recommend you to install another Python interpreter e.g. via brew. See www.brew.sh for more info.
Then, it is just a matter of installing Python via
$ brew install python3
After that, simply install your keyboard package again:
$ pip3 install keyboard
That is a error in your script, you probably didnt import the keyboard module before you used. Try adding this in the first lines of your python script:
import keyboard

Module not found when using sudo on Raspberry Pi (Buster), Kernel 4.19, python 2.7

I'm Getting
ImportError: No module named lirc
when running
sudo python myprog.py
But when I run
python myprog.py
(without sudo)
I don't get the problem. I have to use sudo because my code requires root to get an uncached set of available wifi's.
Any idea what the problem could be please?
try:
sudo -H pip2 install lirc
It seems to me that you dont have lirc installed on system level.

Unable to open python on linux

I know this may be the most silliest questions to be asked but i'm suddenly not able to open python from terminal.
I have python 2.7 installed on ubuntu 14.04 box, but now when i fire python on my command line i get the error
aman#L-JZCHG32:~$ python
The program 'python' is currently not installed. You can install it by typing:
sudo apt-get install python-minimal
I have tried reinstalling python
sudo dpkg -P python2.7
sudo apt-get install python2.7
but it still wont work. Can somebody suggest me what went wrong and how can i correct it.
Thanks.
It seems you've probably corrupted your PATH variable. Try /usr/bin/python in the terminal. If that works, you'll need to fix your PATH variable.
A quick fix would be export PATH=/usr/bin:$PATH but there's probably something not quite right with the whole path variable at the moment, which would be worth further examining.

Install tkinter and python locally

I work with linux on a servies. And I don't have the root privilege. I installed the python-3.2.3 locally to "/home/sam/install_sam". when I import the tkinter module. I get the following error:
ImportError: No module named _tkinter, please install the python-tk package
I know I need to install the Tkinter module. because I don't have the root privilege. I can't use like the following commands:
apt-get install python-tk
sudo apt-get install python-tk
And I search on goolge. I get tcl/tk from here. I install them use the following commands.
cd ~/Downloads/tcl8.5.11/unix
./configure --prefix=/home/sam/install_sam/tcl
make
make install
cd ~/Downloads/tk8.5.11/unix
./configure --prefix=/home/sam/install_sam/tk
--with- tcl=/home/sam/Downloads/tcl8.5.11/unix
make
make install
cd ~/Downloads/Python3.2.3/
export LD_LIBRARY_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
export LD_RUN_PATH=/home/sam/install_sam/tcl/lib:/home/sam/install_sam/tk/lib
./configure --prefix=/home/sam/install_sam/python
make
make install
I still got error: INFO: Can't locate Tcl/Tk libs and/or headers. How should I config the tcl/tk for the python
Use CPPFLAGS environment variable to set the include directories for tcl and tk before building Python 3. This has worked for me.
export CPPFLAGS="-I/home/sam/install_sam/tcl/include -I/home/sam/install_sam/tk/include"
Finally. I install tcl/tk and python in a same path. It can work now. the commands as follow:
cd ~/Downloads/tcl8.5.11/unix
./configure --prefix=/home/sam/install_sam/python3
make
make install
cd ~/Downloads/tk8.5.11/unix
./configure --prefix=/home/sam/install_sam/python3
--with-tcl=/home/sam/Downloads/tcl8.5.11/unix
make
make install
export LD_LIBRARY_PATH=/home/sam/install_sam/python3/lib
cd ~/Downloads/Python3.2.3/3
./configure --prefix=/home/sam/install_sam/python3
make
make install
someone can tell me how to config the tcl/tk for python in the first way(mentioned in the question). I'll appreciate it
sudo apt-get install tcl-dev tk-dev
worked for me, although I ended up pulling a docker image and using that instead.
In my case I had import tkinter properly working on my Python3 environment, but I had to use a pre-compiled Python with its own environment (Blender fyi) that didn't include the dependencies (I needed tkinter to run matplotlib).
The fix in my case was very simple:
In the working python, import tkinter and check where it is installed with tkinter.__file__. This will be something like path/to/site-packages/tkinter
Copy the tkinter folder into the site-packagesof your target installation
Then import _tkinter won't work. Again using the file trick, locate the missing .so file, in my Ubuntu was something like `path/to/python3.7/lib-dynload/_tkinter.cpython-37m-x86_64-linux-gnu.so'
Again, copy the .so file into the corresponding lib-dynload of your target installation. Make sure that both origin and target Python versions are compatible.
To make sure that your target python finds the copied files, make sure that the destination paths are listed under sys.path.
Hope this helps!
Cheers,
Andres
For CentOS, this is:
yum install -y tcl-devel tk-devel
Worked on CentOS 7.
In general, I find that where RHEL has *-dev, CentOS has *-devel

How to compile pygtk from source for python2.6 on ubuntu 12.04

I have a application which is stuck at python2.6. I cannot port it to python2.7 due to specific and complicated extensions.
The probleme is that 12.04 removes pygtk for python2.6 as python2.7 becomes the default python version.
I need then to build pygtk for python2.6 from source. I have followed the readme but I am doing something wrong. (the doc is quite succinct)
The build looks ok, as I can import gtk if I am in the decompressed archive folder (I do a python -c 'import gtk').
But the make install doesn't work properly.
AFAICT, I have export'ed PYTHON & PYTHONPATH variables to the proper path.
PYTHONPATH=/usr/lib/python2.6/dist-packages
PYTHON=/usr/bin/python2.6
Any idea on what's wrong with this config ?
I don't know if I'm getting farther than you are, but here's what I'm doing so far. Maybe we can figure this out together.
$ sudo su
# pip install pygtk
This generates a bunch of errors, including "To build PyGTK in a supported way, read the INSTALL file." After reading that and other things, I tried this:
# cd build/pygtk
# chmod 755 configure
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
This finds the right version of Python, but now can't find GLIB. Errors include, "This usually means GLIB is incorrectly installed." When I look in config.log I find this error, "fatal error: glib.h: No such file or directory". I found a help page that suggested you might get this error if you haven't installed a development version of GLIB.
# apt-get install libglib2.0-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
Progress! I now see a new error, "No package 'pygobject-2.0' found". That error appears in a forum post with a suggestion to install python-gobject-dev.
# apt-get install python-gobject-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
No errors, so I try running make and make install. The first one works, but the install fails with an error, "/bin/bash: line 16: ../py-compile: Permission denied". Permission denied is weird when running as root. After flailing for a while, I go back to the output of the configure script and see a message, "checking for PYCAIRO... no", followed by another, "not checking for gtk due to missing pycairo". A little guesswork leads me to install another module.
# apt-get install python-cairo-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
That solves the pycairo complaint, but there are a bunch more, including GTK.
# apt-get install python-gtk2-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
That solved most of the complaints, just LIBGLADE is missing.
# apt-get install libglade2-dev
# PYTHON=/usr/bin/python2.6 ./configure --prefix=/usr
OK, all the modules will be built, but it says, "Numpy support: no".
# make
# make install
This fails with the same error I saw earlier, "/bin/bash: line 16: ../py-compile: Permission denied".
I'm going to leave it here for now and come back to it later.
Try to use easy_install for 2.6, suppose in your ubuntu you have 2.6 and 2.7 installed. you can have easy_install (by default for 2.7), and easy_install-2.6 to install the dedicated packages for 2.6.

Categories

Resources