xyt_924

python - ImportError:Windows 上没有名为站点的模块

all

正在尝试第一次安装 Python。从 Python 网站下载了以下安装程序:Python 2.7.1 Windows Installer (Windows binary – 不包括源代码)。然后运行安装程序,选择“所有用户”,一切都很好。将 Python 安装到默认位置:

C:\Python27

接下来,为了测试 Python 是否安装正确,导航到的 Python 目录,并在 windows cmd 提示符下运行“python”命令。它返回以下错误:

ImportError:没有名为站点的模块

当执行“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 #恢复 sys.stdout
#restore sys.stderr #cleanup main
#cleanup [1 ] zipimport #cleanup [1] 信号
#cleanup[1 ] exceptions #cleanup [1] _warnings
#cleanup sys #cleanup builtin
#cleanup ints: 6 unfreed ints #cleanup 浮动

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

C:\Users\Mimminito>dir C:\Python27\Lib\site.py*
驱动器 C 中的卷没有标签。
卷序列号为 DAB9-A863

C:\Python27\Lib 目录

2010 年 11 月 13 日20:08 20,389 site.py
1 文件 20,389 字节
0 目录 694,910,976 字节免费

有任何想法吗?


阅读 2262

收藏
2022-09-20

共4个答案

admin

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

  1. 设置 PYTHONPATH / PYTHONHOME变量

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

希望这可以帮助!

2022-09-20
admin

快速解决方案:设置 PYTHONHOME 和 PYTHONPATH 并在 PATH 中包含 PYTHONHOME

例如,如果你安装到 c:\Python27

set PYTHONHOME=c:\Python27
set PYTHONPATH=c:\Python27\Lib
set PATH=%PYTHONHOME%;%PATH%

确保 PYTHON* 变量上没有尾随的 ‘\‘,这似乎破坏了它。

2022-09-20
admin

在安装 Windows Python 和 Cygwin Python 并尝试从 Cygwin 运行 Cygwin Python 后,遇到了这个问题。export通过 PYTHONHOME=/usr/ 和 PYTHONPATH=/usr/lib/python2.7解决了它

2022-09-20
admin

2022-12-13