小编典典

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

python

我最近重新安装了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几次。我可以从这里做什么?谢谢


阅读 166

收藏
2020-12-20

共1个答案

小编典典

对于Python-3,请尝试删除虚拟环境文件。并重新设置它。

rm -rf venv
virtualenv -p /usr/bin/python3 venv/
source venv/bin/activate
pip install -r requirements.txt

https://wiki.ubuntu.com/XenialXerus/ReleaseNotes#Python_3
编辑

2020-12-20