【问题标题】:Running Python 2.7 gives error运行 Python 2.7 会出错
【发布时间】:2016-01-05 11:50:41
【问题描述】:
File "/usr/lib/python2.7/site.py", line 563, in <module>
    main()

这是我使用 Python 运行 ubuntu 14.04 时收到的错误。

Python 3 工作正常,但在运行脚本或使用 Python 解释器时会出现此错误。

完整跟踪:

File "/usr/lib/python2.7/site.py", line 563, in <module>
    main()
  File "/usr/lib/python2.7/site.py", line 545, in main
    known_paths = addusersitepackages(known_paths)
  File "/usr/lib/python2.7/site.py", line 272, in addusersitepackages
    user_site = getusersitepackages()
  File "/usr/lib/python2.7/site.py", line 247, in getusersitepackages
    user_base = getuserbase() # this will also set USER_BASE
  File "/usr/lib/python2.7/site.py", line 237, in getuserbase
    USER_BASE = get_config_var('userbase')
  File "/usr/lib/python2.7/sysconfig.py", line 578, in get_config_var
    return get_config_vars().get(name)
  File "/usr/lib/python2.7/sysconfig.py", line 524, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/usr/lib/python2.7/sysconfig.py", line 408, in _init_posix
    from _sysconfigdata import build_time_vars
  File "/usr/lib/python2.7/_sysconfigdata.py", line 6, in <module>
    from _sysconfigdata_nd import *
ImportError: No module named _sysconfigdata_nd

这个错误似乎是路径错误,我最近也安装了 wxPython,但没有对路径进行任何更改。

编辑:

我重置了我的 Python 路径,但我现在遇到了一个不同的错误,希望在调试方面这是一件好事。

新错误:

Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
ImportError: No module named site

【问题讨论】:

  • 你看过这个问题吗? stackoverflow.com/questions/15608236/…
  • 是的,我已经搜索了好几天,没有运气。我最近遇到的那个,但没有区别,同样的错误。
  • 我发现了一些东西,我重置了 Python 路径,现在出现了一个新错误。
  • 尝试在 Ubuntu 命令行中执行 export PYTHONHOME=&lt;prefix&gt;[:&lt;exec_prefix&gt;]。或unset PYTHONHOME.
  • 我相信我想通了,我有两个两个版本的 python,一个来自 anaconda,一个来自基础安装,每个都试图互相拧。

标签: python python-2.7 ubuntu


【解决方案1】:

安装 anaconda 后我遇到了同样的问题。当我尝试在 anaconda 环境中使用 python 控制台时,我收到了这个错误。下面的代码解决了我的问题。

cd /usr/lib/python2.7
sudo ln -s plat-x86_64-linux-gnu/_sysconfigdata_nd.py .

【讨论】:

    【解决方案2】:

    此错误是由 Anaconda 堆栈尝试使用 Python 引起的。从路径中删除 Anaconda 堆栈修复了此错误。

    我通过查看 ~/.bashrc 文件并注释掉源声明,从路径中删除了 Anaconda 堆栈。当您想再次使用 Anaconda 时,可以取消注释。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-04
      • 1970-01-01
      • 1970-01-01
      • 2015-10-01
      相关资源
      最近更新 更多