当我在Win10上的Spyder IDE中运行以下命令时:
import PIL
import os
Inboundfile = "C:/Test/test/Overlay.png"
image = PIL.Image.open(os.path.abspath(Inboundfile))
image.show() 它工作得很好。打开图片并输出:
runfile('C:/Users/bob/Anaconda3/envs/NewEnvironment/bob/test3.py', wdir='C:/Users/bob/Anaconda3/envs/NewEnvironment/bob')但当我从cmd提示符调用相同的脚本时:
C:\Users\bob\Anaconda3\envs\NewEnvironment\bob>python test3.py其结果是:
Traceback (most recent call last):
File "test3.py", line 14, in <module>
image = PIL.Image.open(os.path.abspath(Inboundfile))
AttributeError: module 'PIL' has no attribute 'Image'我已经验证了环境路径指向与IDE相同的python环境。(我想)下面是我在OS中的Path变量
C:\Users\bob\Anaconda3\envs\NewEnvironment\ 这可能是非常简单的事情,但我在这方面非常新手,任何帮助都将不胜感激。
我尝试添加以下代码行:
from PIL import Image它仍然可以在IDE中正常运行,但错误消息更改为:
C:\Users\bb\Anaconda3\envs\NewEnvironment\bob>python test3.py
Traceback (most recent call last):
File "test3.py", line 11, in <module>
from PIL import Image
File "C:\Users\bob\Anaconda3\envs\NewEnvironment\lib\site-packages\PIL\Image.py", line 69, in <module>
from . import _imaging as core
ImportError: DLL load failed: The specified module could not be found.这甚至更令人困惑,因为我可以沿着该路径看到目录中的Image.py。IDE在做什么,而CMD不是呢?
发布于 2020-03-27 07:32:10
当我简单地关闭并重新启动我用来调用python脚本的控制台时,所有的问题都消失了。我了解到控制台在启动时会保存path变量等内容,并且必须重新启动才能获得更改。
https://stackoverflow.com/questions/60874307
复制相似问题