在我的conda环境中导入matplotlib时导入错误:无法从“PIL”导入名称“\u imaging”

2024-05-23 17:36:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我是这个领域的新手,很抱歉可能会犯愚蠢的错误。 我与snakemake合作,因此我按照他们的指示创建了一个conda环境:

conda install -c conda-forge mamba
mamba create -c conda-forge -c bioconda -n snakemake snakemake

但是,当我运行基本教程(enter link description here)时,发生了ModuleNotFoundError:

snakemake --cores 1

ModuleNotFoundError: No module named 'matplotlib'

因此,我已使用conda forge安装matplotlib:

conda install -c conda-forge matplotlib 

然而,当我重新运行教程时,我得到了一个可怕的消息:

ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/init.py) So I decided to install in the same conda environment also pillow:

conda install -c conda-forge pillow 

但是我在运行教程时遇到了同样的错误

所有导入的软件包都来自my conda环境:

anaconda3/envs/snakemake/lib/python3.9/site-packages

除PIL/枕头路径外,该路径从以下位置导入:

usr/lib/python3/dist-packages

我还更新了conda、anaconda和snakemake环境中的所有包。此外,我用conda list检查了PIL的存在,它实际存在于我的蛇形环境中,路径与其他软件包(anaconda3/envs/snakemake/lib/python3.9/site软件包)相同

我注意到,在其他问题中,建议卸载并重新安装枕头。 但是,当我尝试卸载时:

pip uninstall Pillow

pip3 uninstall Pillow

我获得:

PermissionError: [Errno 13] Permesso negato: 'BlpImagePlugin.cpython-38.pyc'

因此,我尝试强制升级:

pip install -U Pillow --user

pip3 install -U Pillow --user

终端声明我已经成功安装了Pillow 8.0.1。但是,当我导入matplotlib时,会发生相同的错误:

ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/init.py)

我很感激你给我的任何提示 多谢各位


Tags: installpil环境matplotliblibpackagesusrdist
2条回答

我猜你错过了教程(https://snakemake.readthedocs.io/en/stable/tutorial/setup.html)设置中的一个部分。在步骤2中,下载environment.yaml并使用它安装所有需要的软件包。或者您可以自己尝试安装所有软件包,请查看“需求”下的列表

解决了从系统PIL包卸载的问题:

sudo apt-get remove python-pil

我仍然不知道它为什么会工作,但至少现在我可以正确地使用matplotlib

相关问题 更多 >