Python/IPython ImportError:没有名为site的模块

use*_*779 20 python linux ipython importerror ubuntu-12.04

我有python 2.7.3ipython 1.2启动和运行正常我的Linux系统(ubuntu 12.04),但要安装所需的课程matplotlab的更新版本.

在终端中运行此代码行后

user$ sudo easy_install -U distribute
user$ export PYTHONHOME=/usr/lib/python2.7/
Run Code Online (Sandbox Code Playgroud)

现在,每次我尝试运行pythonipython收到错误消息

ImportError: no module named site
Run Code Online (Sandbox Code Playgroud)

我该如何反转/解决这个问题?我迷路了.我看了其他类似的问题,但没有其他人使用Linux,我不知道该怎么办.

Mar*_*n W 18

尝试取消设置你的python路径......

在Linux/Mac中,您可以使用以下命令:

unset PYTHONPATH
unset PYTHONHOME
Run Code Online (Sandbox Code Playgroud)


E.Z*_*.Z. 17

PYTHONHOME

更改标准Python库的位置.默认情况下,在前缀/ lib/pythonversion和exec_prefix/lib/pythonversion中搜索库,其中prefix和exec_prefix是依赖于安装的目录,两者都默认为/ usr/local.

当PYTHONHOME设置为单个目录时,其值将替换prefix和exec_prefix.要为这些值指定不同的值,请将PYTHONHOME设置为前缀:exec_prefix.

尝试清理你的PYTHONHOME:

user$ export PYTHONHOME=
Run Code Online (Sandbox Code Playgroud)

至于安装matplotlib,我建议如下:

sudo apt-get install python-matplotlib
Run Code Online (Sandbox Code Playgroud)

(详情请点这里)

  • 出口PYTHONHOME =/usr /为我做了 (3认同)
  • 嗨,欢迎你.如果这对您有用,请接受答案,这也将从未答复的问题列表中删除您的问题.干杯 (2认同)

jco*_*ctx 10

您可以unset PYTHONHOME使用系统默认值,或export PYTHONHOME=/usr指定前缀,Python将附加'/lib/python2.7'(或其恰好的任何版本)来定位其库.

如果你export PYTHONHOME=/usr/lib/python2.7,Python在不存在的文件夹中查找库/usr/lib/python2.7/lib/python2.7.

如果您export PYTHONHOME=,您正在告诉Python lib在当前工作目录中查找:

jcomeau@aspire:~$ PYTHONHOME= strace -estat64 /usr/bin/python
stat64("lib/python2.7/", 0xff870ee0)    = -1 ENOENT (No such file or directory)
stat64("lib/python2.7", 0xff870ee0)     = -1 ENOENT (No such file or directory)
stat64("lib", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0
stat64("lib/python2.7/", 0xff873efc)    = -1 ENOENT (No such file or directory)
stat64("lib/python2.7/plat-i386-linux-gnu", 0xff870ee0) = -1 ENOENT (No such file or directory)
stat64("lib/python2.7", 0xff870ee0)     = -1 ENOENT (No such file or directory)
stat64("lib", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0
stat64("lib/python2.7/plat-i386-linux-gnu", 0xff873efc) = -1 ENOENT (No such file or directory)
stat64("lib/python2.7/lib-tk", 0xff870ee0) = -1 ENOENT (No such file or directory)
stat64("lib/python2.7", 0xff870ee0)     = -1 ENOENT (No such file or directory)
stat64("lib", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0
stat64("lib/python2.7/lib-tk", 0xff873efc) = -1 ENOENT (No such file or directory)
stat64("lib/python2.7/lib-old", 0xff870ee0) = -1 ENOENT (No such file or directory)
stat64("lib/python2.7", 0xff870ee0)     = -1 ENOENT (No such file or directory)
stat64("lib", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0
stat64("lib/python2.7/lib-old", 0xff873efc) = -1 ENOENT (No such file or directory)
stat64("lib/python2.7/lib-dynload", 0xff870ee0) = -1 ENOENT (No such file or directory)
stat64("lib/python2.7", 0xff870ee0)     = -1 ENOENT (No such file or directory)
stat64("lib", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0
stat64("lib/python2.7/lib-dynload", 0xff873efc) = -1 ENOENT (No such file or directory)
ImportError: No module named site
Run Code Online (Sandbox Code Playgroud)