Konrad Rudolph
Konrad Rudolph

Reputation: 546073

Python fails after deleting site.py

tl;dr

I accidentally deleted my Python installation’s site.py file. Now, when trying to start Python, it complains,

ImportError: Couldn't find the real 'site' module

I tried downloading a site.py from setuptools but this results in an infinite recursion in the __boot method around the statement imp.load_module('site',stream,path,descr) (line 37).

Is there a way to fix this without reinstalling Python? What is the site.py file supposed to do?

Some background information:

This is on a Linux server with a custom Python installation in my home directory (~/nfs, to be precise). There are other Python installations on the server (not mine – it’s a mess!) but $PATH and $PYTHONPATH are set up in such a way as to find my installation first.

As to why I deleted the site.py file: I tried executing a setuptools setup.py script and the script told me to delete the file because it “was not created by setuptools”. I foolishly complied.

I suspect that this original error message was caused by the fact that the setuptools implementation is not mine.

Upvotes: 4

Views: 1821

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124718

The site module sets up your python module search path and some other things. It is somewhat crucial to the normal operation of python.

You can download a new copy from the python source repository:

For other python versions, generally the URL is http://hg.python.org/cpython/file/*major*.*minor*/Lib/site.py for the correct tagged version, then select the raw link in the left-hand menu.

If you installed python from a linux distribution package on Ubuntu or Debian, then this file has been customized and you'll need to re-install the appropriate python-minimal package.

Upvotes: 2

Related Questions