ImportError:没有名为“编码”的模块

新手上路,请多包涵

我最近重新安装了 ubuntu 并升级到 16.04 并且不能使用 python:

 $ python manage.py runserver
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Aborted

此时,python本身不起作用

$ python
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Aborted

甚至这个建议也不再有效:

 unset PYTHONHOME
unset PYTHONPATH

每次我以一种方式修复它,它都会再次出现。几个答案有助于暂时修复它,但不是很好。我已经多次重新安装了python和python3。我能从这里做什么?

原文由 codyc4321 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.5k
2 个回答

对于 Windows10 用户。

我在 Windows10 上使用 python3.4。我安装了python3.5。我找不到 PYTHONPATH、PYTHONHOME 环境变量。如果我在 CMD 控制台中命令 python,它会继续使用 python3.4。我删除了python3.4。每当我在 CMD 控制台中命令 python 时,它就会开始显示如下错误。

 Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

我搜索以找出我的问题。解决方案很简单。安装python3.5时可以自定义安装,在高级选项中勾选 Add Python to environment variables

我离开这里只是为了防止有人遇到类似问题访问这里,这样他们就不会浪费宝贵的时间来解决问题。

原文由 Jayground 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题