Python fails after deleting site.py

五迷三道 提交于 2019-12-10 15:18:39

问题


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.


回答1:


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 python 2.7
  • For python 3.2

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.



来源:https://stackoverflow.com/questions/11410792/python-fails-after-deleting-site-py

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!