我在使用 Conda 时遇到问题。 我正在集群(red hat linux)上工作,我成功地使用了 Conda,创建了一个名为
envname
(包含 Python 2.7)的环境并安装了一些模块。
有一天我登录并尝试启动 Conda 时出现此错误(conda activate envname
或一些简单的命令如 conda info
):
Could not find platform independent libraries `<prefix>`
Consider setting $PYTHONHOME to `<prefix>[:<exec_prefix>]`
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = '/path/to/anaconda3/bin/python'
isolated = 0
environment = 1
user site = 1
import site = 1
sys._base_executable = '/path/to/anaconda3/bin/python'
sys.base_prefix = '/tmp/build/80754af9/python_1593706424329/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho'
sys.base_exec_prefix = '/path/to/anaconda3'
sys.executable = '/path/to/anaconda3/bin/python'
sys.prefix = '/tmp/build/80754af9/python_1593706424329/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho'
sys.exec_prefix = '/path/to/anaconda3'
sys.path = [
'/tmp/build/80754af9/python_1593706424329/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/python38.zip',
'/tmp/build/80754af9/python_1593706424329/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placeho/lib/python3.8',
'/path/to/anaconda3/lib/python3.8/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fbecd9dd740 (most recent call first):
`<no Python frame>`
我的目标是让 conda 使用我之前创建的虚拟环境再次运行,而无需从头开始安装所有东西。
我试图查找类似的线程但无法解决问题。 一些可能相关的信息:
通过执行 source activate envname(我通常做的 ti 激活虚拟环境)它给出了错误
-bash: activate: File o directory non esistente
如果我在登录集群后立即使用
python
命令,我有一个函数python(2.7版)。不出所料,它并没有安装我在conda环境中安装的所有模块。
使用命令
which python
可以看到这个python版本位于/usr/bin/python。
这个文件夹不是我在集群上的个人文件夹,而是一个全局文件夹。
所以我想探索这里提出的解决方案(Could not find platform independent libraries 如果我尝试使用手动设置 PYTHONHOME 变量
export PYTHONHOME=/usr/bin/python
,不仅conda不行,python命令也不行,报错“could not import site”
如果我尝试将 PYTHONPATH 和 PATH 变量以及 PYTHONHOME 变量设置为相同的路径,情况仍然如此。
如果我取消设置 PYTHONHOME 和其他路径,或者退出集群然后再次登录,python 将按照第一个要点中的描述工作。
如果我将 /path/to/anaconda3/bin/python 用于 PYTHONHOME、PYTHONPATH 和 PATH 而不是 /usr/bin/python,情况也是如此(它只会更改显示更新路径的错误消息)
在 PATH 中有以下路径:'/path/to/anaconda3/condabin'、'/usr/bin'(以及其他路径)。 如果我将
export PATH=$PATH:/path/to/anaconda3/bin
行附加到 .bashrc 并再次获取 .bashrc 文件,问题仍然存在。 (这里建议了这个解决方案找不到我的 conda 环境)
我认为,conda 尝试使用的 python 安装有问题。特别是,Python 无法找到它需要运行的编码模块。甚至有一次我遇到这个问题
解决这个问题,可以尝试将PYTHONHOME环境变量设置为你的Python安装所在的路径。 使用这个命令
export PYTHONHOME= "python installation path without double quotes"
如果这不起作用,那么试试这个
conda activate envname
pip install --upgrade --force-reinstall --no-cache-dir encodings
如果两者都不起作用,您可能需要尝试重新安装 Conda 或从头开始创建新的虚拟环境。