I’m totally confused with new python 2.7.10.
I've installed python 2.7.10 from tar.xz, which was downloaded from official site. Then I've linked /usr/local/bin/python2.7 with /usr/bin/python2.7 and /usr/bin/python, but when I try to import module, I get ImportError: No module named "module_name". For example:
python -c "import gtk"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named gtk
But if:
cd /usr/lib/python2.7/dist-packages/gtk-2.0/
python -c "import gtk"
We get:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "gtk/__init__.py", line 30, in <module>
import gobject as _gobject
ImportError: No module named gobject
So, gtk module has been imported successfully.
Let's "cd ~" and look at sys.path:
python -c "import sys, pprint; pprint.pprint(sys.path)"
['',
'/usr/local/lib/python2.7/site-packages/setuptools-17.1.1-py2.7.egg',
'/usr/local/lib/python2.7/site-packages/pip-7.1.0.dev0-py2.7.egg',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
Ok, there is no /usr/lib/python2.7/dist-packages, let's add it:
export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7
Now:
python -c "import sys, pprint; pprint.pprint(sys.path)"
['',
'/usr/local/lib/python2.7/site-packages/setuptools-17.1.1-py2.7.egg',
'/usr/local/lib/python2.7/site-packages/pip-7.1.0.dev0-py2.7.egg',
'/home/s-quark',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
But it's still could not find module:
python -c "import gtk"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named gtk
What I have to do?
gtk-2.0path in all of your lists, just because you havedist-packagesdoesn't mean you have the subdirectories :) Regardless, I would recommend starting over and using a packaging manager to handle the installing of Python and the libraries.sudo pip install PyGTKI get:No matching distribution found for PyGTKThen when I try something with gtk in dependencies:sudo pip install pygtk-shellI get: ` import gtk ImportError: No module named gtk ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-y3ju0c/pygtk-shell`which -a python? They don't recommend doingsudo pip installinstead create a virtual environment instead. After that usepython -m pip installto make sure you use the virtual environment. Generally stay away fromsudoalias pythonA='$HOME/anaconda/bin/pythonin your~/.bashrc. Then you can install everything withpythonA -m pip installand avoid messing up your system.