简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM