Python / IPython的ImportError:没有模块命名的网站

我已经在我的Linux系统( ubuntu 12.04 )上正确运行了python 2.7.3ipython 1.2 ,但试图安装课程所需的matplotlab的更新版本。

在terminal中运行此代码行后

 user$ sudo easy_install -U distribute user$ export PYTHONHOME=/usr/lib/python2.7/ 

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

 ImportError: no module named site 

我如何扭转/解决这个问题? 我很迷茫 我看了其他类似的问题,但没有人使用Linux ,我不知道该怎么做。

Solutions Collecting From Web of "Python / IPython的ImportError:没有模块命名的网站"

PYTHONHOME

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

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

尝试清理你的PYTHONHOME

 user$ export PYTHONHOME= 

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

 sudo apt-get install python-matplotlib 

(详情在这里 )

试着去取消你的Python路径…

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

 unset PYTHONPATH unset PYTHONHOME 

您可以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