我在python 2.7.3
系统(ipython 1.2
)上正常运行Linux
和ubuntu 12.04
但是正在尝试安装课程所需的matplotlab的更新版本。< / p>
在终端中运行此代码行
user$ sudo easy_install -U distribute
user$ export PYTHONHOME=/usr/lib/python2.7/
现在,每当我尝试运行python
或ipython
时,我都会收到错误消息
ImportError: no module named site
如何解决/解决此问题?我迷路了。我查看了其他类似的问题,但没有其他人使用Linux
,我不知道该怎么办。
答案 0 :(得分:16)
更改标准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
(详情here)
答案 1 :(得分:16)
尝试取消设置你的python路径......
在Linux / Mac中,您可以使用以下命令:
unset PYTHONPATH
unset PYTHONHOME
答案 2 :(得分:9)
您可以unset PYTHONHOME
使用系统默认值,或export PYTHONHOME=/usr
指定Python将附加的前缀&#39; /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