Python error after site.py removal

TL; DR

I accidentally deleted the site.py Python site.py . Now, trying to run Python, he complains

ImportError: could not find the real site module

I tried loading site.py from setuptools , but this leads to infinite recursion in the __boot method around the imp.load_module('site',stream,path,descr) (line 37).

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

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 set up to find my installation first.

Why I deleted the site.py file: I tried to execute setuptools setup.py script, and the script told me to delete the file because it "was not created by setuptools". I acted stupidly.

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

+4
source share
1 answer

The site module sets your python module search path and some other things. This is somewhat important for python to work properly.

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

For other versions of python, usually 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 menu.

If you installed python from a linux distribution on Ubuntu or Debian, this file has been configured, and you will need to reinstall the corresponding minimal python package.

+2
source

All Articles