【问题标题】:Python/IPython ImportError: no module named sitePython/IPython ImportError:没有名为站点的模块
【发布时间】:2014-03-19 10:11:24
【问题描述】:

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

在终端运行此代码行后

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

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

ImportError: no module named site

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

【问题讨论】:

标签: python linux ubuntu-12.04 ipython importerror


【解决方案1】:

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

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

unset PYTHONPATH
unset PYTHONHOME

【讨论】:

  • 用cygwin安装python后,遇到了这个问题。一个旧版本的 python 已由 Windows 程序安装,这就是 cygwin 放入 PYHONHOME 变量的内容。一旦我在 cygwin 中如上所述取消设置 python 工作正常
  • 完美答案!
  • 为 rhel7 工作
【解决方案2】:

PYTHONHOME

更改标准 Python 库的位置。默认情况下, 在 prefix/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

【讨论】:

  • 是的!成功了,非常感谢!使用 apt-get install 访问的 matplotlib 版本不是最新版本...我尝试使用 sudo pip install --upgrade matplotlib 但它正在运行“命令 python setup.py egg_info failed with error code 1”。我可能会保留它,明天尝试解决它。​​
  • 嗨,不客气。如果这对您有用,请接受答案,这也会将您的问题从未回答的问题列表中删除。干杯
  • export PYTHONHOME=/usr/ 为我做的
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    相关资源
    最近更新 更多