What should I install in order to be able to use GTK in Python on Ubuntu?
In my source code I have:
import gtk
But when I run the script with python3 script.py command I get the following error. What package should I install to get it working?
Edit: my bad. here is the error:
ImportError: No module named gtk
Edit2: Thanks for the answer, kaizer.se. But I'm still getting an error message. Take a look at the following code: import pygtk, gtk pygtk.require('2.0')
def main():
win = gtk.Window(gtk.WINDOW_TOPLEVEL)
s = u"привет 한국"
win.set_title(s)
win.connect("destroy", gtk.main_quit)
win.show()
if __name__ == "__main__":
main()
gtk.main()
When I run this script I get the following error:
SyntaxError: Non-ASCII character '\xd0' in file basics.py on line 6, but no encoding declared; see python.org/peps/pep-0263.html for details
Any idea how I may solve this problem? Thanks.
Asked by: Catherine366 | Posted: 27-01-2022
Answer 1
PyGtk doesn't support Python 3 yet. You might want to use Python 2.x and then you will need to install the python-gtk2
package.
Answer 2
There is no big difference between how Python 3 and Python 2.6 handle unicode and international text, technically. The biggest difference is what the classes are called and what the defaults are.
So if you in Python 3 write:
s = "Grüß Gott"
you take this in Python 2.x:
# coding: UTF-8
s = u"Grüß Gott"
PyGTK always works with the UTF-8 encoding internally, and you can pass it unicode strings or UTF-8-encoded strings however you want.
The best model is to always work with unicode strings internally, and always convert strings as soon as they enter your program (say, you read a file). Again, in Python 3 this is more explicitly enforced, but the process is really exactly the same.
Addessing the updated question: I have already answered, Look closely at my Py 3 and Py 2.x examples! Hint: You must specify an encoding on the first line of every file, like this: # coding: UTF-8
You must also ask yourself, Baha, when you see an error message like this:
SyntaxError: Non-ASCII character '\xd0' in file basics.py on line 6, but no encoding declared; see python.org/peps/pep-0263.html for details
Did you read the message and see it says "no encoding declared"? Did you follow the link and read the information there? It would have been easy to solve this yourself.
Answered by: Rafael366 | Posted: 28-02-2022Similar questions
python - How to install lxml on Ubuntu
I'm having difficulty installing lxml with easy_install on Ubuntu 11.
When I type $ easy_install lxml I get:
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3
Downloading http://lxml.de/files/lxml-2.3.tgz
Processing lxml-2.3.tgz
Running lxml-2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7UdQOZ/lxml-2.3/egg-dist...
python - How to install PIL in Ubuntu 11.04?
I see this question asked all over the internet, and I've tried following them all, but I still can't get PIL to work.
I tried symbolically linking the zlib, jpeg, etc. libraries via:
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
I tried editing the
python - How to install PIL with ZIP, JPEG, etc. on Ubuntu 11.10
I am trying to be able to import png, which I believe is from the PIL. I would also prefer if JPEG and the others were also working
I am running Ubuntu 11.10.
now from http://jj.isgeek.net/2011/09/install-pil-with-jpeg-support-on-ubuntu-oneiric-64bits/
i have figured a few thing...
python - Cannot install rdkit in ubuntu 11.10
I have spent many hours trying to build RDKit on ubuntu 11.10 for
Python 2.7 (rdkit_201106+dfsg.orig.tar.gz) using a precompiled version
of boost 1.49. And I am failing miserably.
The recurring error is in the CMake GUI:
CMake Error at CMakeLists.txt:11 (install):
install FILES given no DESTINATION!
CMake Error at CMakeLists.txt:14 (add_pytest):
Unknown CMake command "add_pytest".
Python - How do I install Pmw in ubuntu?
In my pydev eclipse appears unresolved imports: Pmw, I've downloaded the Pmw from: http://pmw.sourceforge.net/ http://sourceforge.net/projects/pmw/files/ ,to be specific the Pmw2 one, it comes with a folder called Pwd2, what is supposed that I'm going to do with the folder? thanks.
Install Python 3.3 on Ubuntu
This question already has answers here:
python - Cannot install vim ubuntu 13.10
Closed. This question does not meet Stack Overflow guid...
python - How to install Pisa on Ubuntu
Closed. This question does not meet Stack Overflow guid...
install numpy for python 3.4 in ubuntu
This question already has answers here:
python - Can't install Rodeo with pip on Ubuntu
I can't install Rodeo with pip, on Ubuntu 14.04.2 LTS 64 bit (installed on a Virtual Box)
For information I'm a Python and Ubuntu beginner and I installed pip by following this tutorial
pip -V
pip 6.1.1 from /usr/local/lib/pyth...
python - Fail to install lxml on ubuntu
I am attempting to install lxml inside a virtualenv on ubuntu 14.04.
$ uname -a
Linux foobar 3.13.0-48-generic #80-Ubuntu SMP Thu Mar 12 11:16:15 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
I have the dependencies installed, as specified in the lxml docu...
python - How can I install pyv8 in Ubuntu 14.04?
I installed the libv8 and libboost-all-dev Ubuntu packages, then ran
sudo pip install pyv8
And got:
building '_PyV8' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -DBOOST_PYTHON_STATIC_LIB -Ilib/py...
python - cant install kivy in ubuntu
Closed. This question does not meet Stack Overflow guid...
python - How to install lxml on ubuntu?
First, I have found this question:
How to install lxml on Ubuntu
But after I tried all the answers on that page, it didn't resolve my problem. My problem is:
When I try to install lxml, the error is:
Installing egg-scripts.
uses namespace packages but the distribution ...
python - How to install l2cs on ubuntu 12.04
Closed. This question does not meet Stack Overflow guid...
python - not able to install numpy in ubuntu 14.04
This question already has answers here:
how to install python error free in ubuntu 16.04
I'm new to ubuntu 16.04. somehow I uninstalled my built-in python and again I tried to install using
sudo apt-get install python2.7
but this is the error i got
Reading package lists... Done
Building dependency tree
Reading state information... Done
python2.7 is already the newest version (2.7.12-1ubuntu0~16.04.2).
You might want to run '...
python - Ubuntu conda install pydub
I have ubuntu version 15.10 and anaconda version conda 4.4.10.
My problem is I am trying to install the module/package pydub and the command to do that is:
conda install -c auto pydub #(see https://anaconda.org/auto/pydub)
The error message I am getting is this:
Solving environment: failed
UnsatisfiableError: The following speci...
python - How to install GDAL in Ubuntu?
I've got Ubuntu 17.04 version installed and I want to install GDAL. I have tried several ways to install it, but always I've got an error. I have installed Python 2.7 and Python 3.6 but I want to do the install for Python 2.7
I have tried to do the installation following these steps:
sudo apt-get install libgdal-dev export
CPLUS_INCLUDE_PATH=/usr/include/gdal export
C_INCLUDE_PATH=/usr/include/gdal ...
python - ubuntu 14.04 pyenv install fail
with command "lsb_release -a",
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
I followed this page,
https://github.com/pyenv/pyenv#basic-github-checkout
python - How can I install pyCurl?
I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.
I am on Windows. I tried DLing the sources and use pycurl setup script, but I had no luck.
python - where does django install in ubuntu
I am looking for the init.py file for django. I tried whereis and find, but I get a lot of dirs.
Install python 2.6 in CentOS
I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred it, and did a ./configure --prefix=/opt which is where I want it to end ...
install python Mysql module
I've just installed python 2.6 on my win7 machine.
Now I tried to install mysqldb. But when run "python setup.py install"
C:\MySQL-python-1.2.3c1>python setup.py install
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "C:\MySQL-python-1.2.3c1\setup_windows.py", line 7, in get_config
serverKey = _winreg.OpenKey(_winreg....
boost - I've got Python built using VS2008, how do I install it?
I'm working with boost::python and wanted to build the whole thing to make sure I can pull it off. However, I don't see any install script or way to build the MSI so I can install it.
Anyone know where the directions are? Or the projects I could use to make an MSI file?
Doing this on linux seems trivial:
make install
How do I do this under windows
python - Error install PyGtk
I tried to install pygtk on mac. I downloaded the pygtk file, opened up terminal and set it to my working directory, then ran the command "python setup.py install". There was an import error because there was no module dsextras. Does anyone know how to install pygtk on a mac or get dsextras.
python - How do I install boto?
So that I am able to work with it within my python scripts?
python - How do I install pyCurl?
I tried everything! I cannot find a way to install pyCurl on my Windows 7 machine!
I found these binaries link... BUT there are no binaries for 2.6. : (
Help would be great. : )
python - What is paster and how do I install it?
I am installing an application and have installed python and easy_install. I now have two steps to complete:
5. Make a config file as follows::
paster make-config openbiblio development.ini
6. Tweak the config file as appropriate and then setup the application::
paster setup-app config.ini
I have read Stackoverflow answers and tried the web but cannot f...
How to install SSL for python 2.5 on Debian Linux?
Question
How do I install SSL for Python 2.5 on Debian?
I have tried:
sudo easy_install ssl
But getting:
$ python setup.py build
looking for /usr/include/openssl/ssl.h
looking for /usr/include/krb5.h
running build
running build_py
running build_ext
building 'ssl._ssl2' extension
creating build/temp.linux-i686-2.5
creating build/temp.linux-i686-2.5/ssl
gcc ...
macos - python install on leopard
I'll admit I'm completely dumbed by python install. Can someone help me on how to install module
I want to play with PyGame, PyOpenGL etc. So I install them, but I everytime I type "import pygame" error message shows up.
here's my environment so far.
In .bash_profile
PATH=${PATH}:/System/Library/Frameworks/Python.framework/Versions/Current/bin
Using easy_install PyO...
python - How can I install pyCurl?
I used libcurl with no problems and used pyCurl once in the past. Now i want to set it up on my machine and dev. However i have no idea how to do it. I rather not DL libcirl files and compile that along with pycurl, i want to know the simplest method. I have libcurl installed on my machine.
I am on Windows. I tried DLing the sources and use pycurl setup script, but I had no luck.
python - where does django install in ubuntu
I am looking for the init.py file for django. I tried whereis and find, but I get a lot of dirs.
python - Install mysqldb on snow leopard
I am trying to get started on working with Python on Django I am by profession a PHP developer and have been told to set up django and python on my current apache and mysql setup however I am having trouble getting the Mysqldb module for python to work, I must of followed about 6 different set of instructions, I am running snow leopard and have mysql installed natively it is not part of MAMP or similar. Please can some tel...
Install python 2.6 in CentOS
I have a shell that runs CentOS.
For a project I'm doing, I need python 2.5+, but centOS is pretty dependent on 2.4.
From what I've read, a number of things will break if you upgrade to 2.5.
I want to install 2.5 separately from 2.4, but I'm not sure how to do it. So far I've downloaded the source tarball, untarred it, and did a ./configure --prefix=/opt which is where I want it to end ...
How to install 64-bit Python on Solaris?
I am trying to install Python 2.6 on Solaris by building the source on Solaris machine. I installed one this way and it appears that it is 32-bit. I downloaded some source tar ball as Linux or Unix for this purpose. Everything works well but I need 64-bit Python.
I looked up the Python download site and there is no sepa...
macos - Install PyObjC on Python 2.6 on OS X 10.5?
OS X 10.5.8 came with Python 2.5, and had PyObjC already installed.
I installed Python 2.6 from the python.org site, and PyObjC isn't there.
I can't find a download to install PyObjC on my Python 2.6 install. Is checking out the PyObjC trunk and trying to build it my only choice? Will that work "out of the box"?
python - How to install numpy and scipy on Windows XP
python - How do I install SciPy on 64 bit Windows?
How do I install SciPy on my system?
For the NumPy part (that SciPy depends on) there is actually an installer for 64 bit Windows: numpy-1.3.0.win-amd64-py2.6.msi (is direct download URL, 2310144 bytes).
Running the SciPy superpack installer results in this
message in a dialog box:...
python - How to install pycairo on osx?
I am trying to install the pycairo (Python bindings for the cairo graphics library) under OSX.
I started with
easy_install pycairo
and got:
Requested 'cairo >= 1.8.8' but version of cairo is 1.0.4
error: Setup script exited with Error: cairo...
Still can't find your answer? Check out these communities...
PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python