Python错误集锦:导入pygifsicle模块时提示FileNotFoundError: The gifsicle library was not found on your system

原文链接:http://www.juzicode.com/python-error-filenotfounderror-the-gifsicle-library-was-not-found-on-your-system

错误提示:

已通过pip安装pygifsicle模块,并显示正常安装:

python -m pip install   pygifsicle

pygifsicle                1.0.5

pygifsicle完成安装后,导入pygifsicle模块时仍然提示FileNotFoundError: The gifsicle library was not found on your system

#juzicode.com / VX公众号:桔子code
import imageio 
from pygifsicle import optimize
gif_name = 'tomandjerry.gif'
optimize(gif_name, "opti.gif") 

运行结果:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
d:\python\python38\lib\site-packages\pygifsicle\pygifsicle.py in gifsicle(sources, destination, optimize, colors, options)
     70     try:
---> 71         subprocess.call(["gifsicle", *options, *sources, "--colors",
     72                         str(colors), "--output", destination])

d:\python\python38\lib\subprocess.py in call(timeout, *popenargs, **kwargs)
    339     """
--> 340     with Popen(*popenargs, **kwargs) as p:
    341         try:

d:\python\python38\lib\subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors, text)
    853 
--> 854             self._execute_child(args, executable, preexec_fn, close_fds,
    855                                 pass_fds, cwd, env,

d:\python\python38\lib\subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, unused_restore_signals, unused_start_new_session)
   1306             try:
-> 1307                 hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
   1308                                          # no special security

FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-7-45fb5fd69e93> in <module>
      3 from pygifsicle import optimize
      4 gif_name = 'tomandjerry.gif'
----> 5 optimize(gif_name, "opti.gif")

d:\python\python38\lib\site-packages\pygifsicle\pygifsicle.py in optimize(source, *args, **kwargs)
     90         Path to gif image to optimize.
     91     """
---> 92     gifsicle(source, *args, **kwargs, optimize=True)

d:\python\python38\lib\site-packages\pygifsicle\pygifsicle.py in gifsicle(sources, destination, optimize, colors, options)
     72                         str(colors), "--output", destination])
     73     except FileNotFoundError:
---> 74         raise FileNotFoundError((
     75             "The gifsicle library was not found on your system.\n"
     76             "On MacOS it is automatically installed using brew when you "

FileNotFoundError: The gifsicle library was not found on your system.
On MacOS it is automatically installed using brew when you use the pip install command.
On other systems, like Linux systems and Windows, it prompts the instructions to be followed for completing the installation.
You can learn more on how to install gifsicle on the gifsicle and pygifsicle documentation.

错误原因:

1、pygifsicle只是gifsicle工具的Python接口,该提示说明环境没有安装gifsicle工具,需要先安装才能正常使用pygifsicle。

解决方法:

1、找到gifsicle官网https://www.lcdf.org/gifsicle/下载安装包,根据自己的系统选择相应的安装包,比如windows系统选择“windows ports”:

安装包下载后再本地解压,比如我的路径为D:\dev\gifsicle-1.92-win64\gifsicle-1.92,在环境变量的path中添加该路径,添加完成后打开新的命令行输入gifsicle –version 确认是否完成安装,如果看到相应的版本号表示安装完成:

> gifsicle --version
LCDF Gifsicle 1.92
Copyright (C) 1997-2019 Eddie Kohler
This is free software; see the source for copying conditions.
There is NO warranty, not even for merchantability or fitness for a
particular purpose.

注意因为重新设置了环境变量,原来的python代码运行需要重新开启命令行界面再次执行,如果使用的是jupyter(notebook)且jupyter的开启也是从命令行启动的,也需要重新开启命令行并重新启动jupyter。

扩展内容:

https://www.lcdf.org/gifsicle/


如果本文还没有完全解决你的疑惑,你也可以在微信公众号“桔子code”后台给我留言,欢迎一起探讨交流。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注