gpt4 book ai didi

python - Windows 上的 "ImportError: No module named site"

转载 作者:IT老高 更新时间:2023-10-28 21:08:23 26 4
gpt4 key购买 nike

我是第一次尝试安装 Python。我从 Python 网站下载了以下安装程序:Python 2.7.1 Windows Installer (Windows binary -- does not include source) .然后我运行安装程序,选择“所有用户”,一切都很好。我将 Python 安装到默认位置:

C:\Python27

接下来,为了测试 Python 是否安装正确,我导航到我的 Python 目录,并在 windows CMD 提示符下执行 python。它返回给我以下错误:

ImportError: No module named site

当我执行 python -v 时,我得到以下信息:

#installing zipimport hook
import zipimport # builtin
#installed zipimport hook
#ImportError: No module named site
#clear builtin._
#clear sys.path
#clear sys.argv
#clear sys.ps1
#clear sys.ps2
#clear sys.exitfunc
#clear sys.exc_type
#clear sys.exc_value
#clear sys.exc_traceback
#clear sys.last_type
#clear sys.last_value
#clear sys.last_traceback
#clear sys.path_hooks
#clear sys.path_importer_cache
#clear sys.meta_path
#clear sys.flags
#clear sys.float_info
#restore sys.stdin
#restore sys.stdout
#restore sys.stderr
#cleanup main
#cleanup [1] zipimport
#cleanup [1] signal
#cleanup [1] exceptions
#cleanup [1] _warnings
#cleanup sys
#cleanup builtin
#cleanup ints: 6 unfreed ints
#cleanup floats

当我执行 dir C:\Python27\Lib\site.py* 时,我得到以下信息:

 Directory of C:\Python27\Lib  

13/11/2010 20:08 20,389 site.py
1 File(s) 20,389 bytes
0 Dir(s) 694,910,976 bytes free

有什么想法吗?

最佳答案

我已经为自己研究了将近一天的这个问题,终于有了突破。试试这个:

  1. 设置 PYTHONPATH/PYTHONHOME 变量

    右键单击开始菜单中的计算机图标,转到属性。在左侧选项卡上,转到高级系统设置。在出现的窗口中,转到高级选项卡,然后在底部单击环境变量。单击用户变量列表并开始键入 Python,然后重复 系统变量,以确保您没有为 PYTHONPATH 或 PYTHONHOME 错误设置变量。接下来,添加新变量(我是在 System 而不是 User 中添加的,尽管它也可能对 User 有效):PYTHONPATH,设置为 C:\Python27\LibPYTHONHOME,设置为 C:\Python27

希望这会有所帮助!

关于python - Windows 上的 "ImportError: No module named site",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5599872/

26 4 0