0

During editting the Django apps, I deleted the python2.7 folder in "usr/lib/python2.7" by mistake.

After that problem happened, I always got the msg as following when using :

Could not find platform independent libraries <prefix> Could not find platform dependent libraries <exec_prefix> Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] ImportError: No module named site

--- os is Ubuntu12.04 ----

I have tried to refer to these pages:

http://bugs.python.org/issue6060,

Python/IPython ImportError: no module named site

and also try to use

sudo apt-get install --reinstall to reinstall the python2.7.8 version

My PYTHONPATH now looks like

PYTHONDIR= usr/local/lib/python2.7,

PYTHONHOME= usr/local/lib/python2.7,

PYTHONPATH=

but I still get "ImportError: No module named site" msg

If I try to type

Import sys

I would get the msg "import: unable to open image `sys': @ error/blob.c/OpenBlob/2587."

I want to know what is my problem now, and how to fix it?

Many thanks,

Community
  • 1
  • 1
Porter Chen
  • 9
  • 2
  • 5
  • it seems like reboot or try http://superuser.com/questions/577430/accidentally-deleted-python-python2-python2-7-files-from-usr-bin-is-it-poss – Porter Chen Aug 24 '14 at 07:36

1 Answers1

3

First, be careful - even restrictive - about what you ever run as root. A normal user could not modify things under /usr/lib, and for good reason - it breaks the system.

Second, you can find out what packages contain things in that directory using:

$ dpkg -S /usr/lib/python2.7
python-qgis, python-gdal, python-psycopg2, python-pyspatialite, youtube-dl, virtualbox, duplicity, bzr-git, bzr-builddeb, debconf, ipython, libpython2.7-minimal:i386, libpython2.7-dev:i386, tahoe-lafs, seascope, samba, qbzr, python2.7, python-zope.interface, python-zfec, python-yaml, python-xdg, python-xapian, python-wxversion, python-wxgtk2.8, python-ws4py, python-webob, python-wadllib, python-vipscc, python-utidylib, python-usb, python-urllib3, python-tz, python-twisted, python-twisted-words, python-twisted-web, python-twisted-runner, python-twisted-news, python-twisted-names, python-twisted-mail, python-twisted-lore, python-twisted-core, python-twisted-conch, python-twisted-bin, python-tk, python-tdb, python-talloc, python-support, python-subversion, python-sphinx, python-software-properties, python-six, python-sip, python-simplejson, python-simplegeneric, python-setuptools, python-setools, python-serial, python-sepolicy, python-sepolgen, python-semanage, python-selinux, python-secretstorage, python-scipy, python-samba, python-routes, python-roman, python-requests, python-repoze.lru, python-reportlab, python-reportlab-accel, python-renderpm, python-radare2, python-qt4, python-qt4-gl, python-qscintilla2, python-pyvorbis, python-pytools, python-pysqlite2, python-pyside.qtxml, python-pyside.qtwebkit, python-pyside.qtuitools, python-pyside.qttest, python-pyside.qtsvg, python-pyside.qtsql, python-pyside.qtscript, python-pyside.qtopengl, python-pyside.qtnetwork, python-pyside.qthelp, python-pyside.qtgui, python-pyside.qtdeclarative, python-pyside.qtcore, python-pyside.phonon, python-pyparsing, python-pyopencl, python-pygments, python-pygame, python-pycurl, python-pycryptopp, python-pyaudio, python-pyasn1, python-poppler-qt4, python-ply, python-pkg-resources, python-pivy, python-pip, python-pil, python-pexpect, python-paramiko, python-pam, python-openssl, python-opengl, python-opencv, python-ogg, python-oauthlib, python-oauth, python-numpy, python-ntdb, python-newt, python-nevow, python-networkx, python-netifaces, python-mysqldb, python-musicbrainz, python-mock, python-mechanize, python-markupsafe, python-markdown, python-mako, python-magic, python-lxml, python-libxml2, python-ldb, python-lazr.uri, python-lazr.restfulclient, python-launchpadlib, python-keyring, python-jinja2, python-ipy, python-imaging, python-httplib2, python-html5lib, python-gtk2, python-gst0.10, python-gst0.10-rtsp, python-gpgme, python-gobject-2, python-glade2, python-gi, python-freenect, python-foolscap, python-feedparser, python-fastimport, python-eyed3, python-enchant, python-egenix-mxtools, python-egenix-mxdatetime, python-ecdsa, python-dulwich, python-docutils, python-docopt, python-dnspython, python-distro-info, python-distlib, python-decorator, python-debian, python-dbus, python-dateutil, python-cssutils, python-cssselect, python-crypto, python-configobj, python-colorama, python-collada, python-cherrypy3, python-chardet, python-bzrlib, python-bluez, python-beautifulsoup, python-audit, python-apt, python-apsw, policycoreutils, mercurial, mercurial-common, lsb-release, iotop, hugin-tools, hplip, frescobaldi, libpython2.7:i386, libpython2.7-stdlib:i386, dblatex, cython, cfv, bzr-upload, bzr-search, bzr-pipeline, bzr-loom, bzr-explorer: /usr/lib/python2.7

(Yes, the list is very long.) Knowing that list, we can request those packages to be reinstalled:

$ sudo apt-get install --reinstall `dpkg -S /usr/lib/python2.7 | sed -e s/,//g -e 's/: .*$//'`

I apologise for the very long command line; the sed command here cleans up the output of dpkg to produce only the list of packages we want to reinstall. This method is likely to help with the specific issue you mention, but even having it occur once suggests you're not clear on the consqeuences of other changes. You may want to slow down and learn more about your system's structure.

Things like PYTHON* variables won't help you much unless you have a precisely matching version of Python elsewhere, something we tend to avoid on Linux distributions because we usually have working (albeit limited) package management.

Lastly, I think the question ends up more of a superuser question than stack overflow.

Yann Vernier
  • 15,414
  • 2
  • 28
  • 26
  • Thanks for reply. I am new to unix-os and I really know that I make a big trouble. I follow the steps you listed, but I still get the "ImportError" msg. Is there anything I need to do before or next? – Porter Chen Aug 24 '14 at 08:24
  • I cannot tell. The `site` module is in that directory, so it should work as long as you *don't* set any `PYTHONHOME` etc variables. – Yann Vernier Aug 24 '14 at 08:28
  • 1
    Yes! That worked, thank you so much! I clean all the PYTHONHOME variables, and it can work now!! Thanks again! – Porter Chen Aug 24 '14 at 08:33
  • Sorry! my bad. I just start learning the thing of "coding". Your patience is very much appreciated:) – Porter Chen Sep 02 '14 at 08:09