关于ghostscript not found 解决方案

来源:互联网 发布:js鼠标经过事件 编辑:程序博客网 时间:2024/05/16 23:02

最近在看Machine Learning - A Probabilistic Perspective这本书,机器学习。MIT出版。

作者:Kevin P Murphy

书的website:http://www.cs.ubc.ca/~murphyk/MLbook/index.html.

今天拿起代码,试着运行了下,出现了一个错误,运行到printPmtkFigure这个函数,出现:“ghostscript not found matlab”, 以前貌似也遇到相似的问题。解决了一早上,终于搞好了。

 

解决方法:

1 下载 Ghostscript, 网址:http://www.ghostscript.com/。

放在c盘。

2 从网上下载ghostscript.m代码,

附上:

%GHOSTSCRIPT  Calls a local GhostScript executable with the input command%% Example:%   [status result] = ghostscript(cmd)%% Attempts to locate a ghostscript executable, finally asking the user to% specify the directory ghostcript was installed into. The resulting path% is stored for future reference.% % Once found, the executable is called with the input command string.%% This function requires that you have Ghostscript installed on your% system. You can download this from: http://www.ghostscript.com%% IN:%   cmd - Command string to be passed into ghostscript.%% OUT:%   status - 0 iff command ran without problem.%   result - Output from ghostscript.% Copyright: Oliver Woodford, 2009-2010% Thanks to Jonas Dorn for the fix for the title of the uigetdir window on% Mac OS.% Thanks to Nathan Childress for the fix to the default location on 64-bit% Windows systems.% 27/4/11 - Find 64-bit Ghostscript on Windows. Thanks to Paul Durack and% Shaun Kline for pointing out the issue% 4/5/11 - Thanks to David Chorlian for pointing out an alternative% location for gs on linux.% 12/12/12 - Add extra executable name on Windows. Thanks to Ratish% Punnoose for highlighting the issue.function varargout = ghostscript(cmd)% Call ghostscript[varargout{1:nargout}] = system(sprintf('"%s" %s', gs_path, cmd));returnfunction path_ = gs_path% Return a valid path% Start with the currently set pathpath_ = user_string('ghostscript');% Check the path worksif check_gs_path(path_)    returnend% Check whether the binary is on the pathif ispc    bin = {'gswin32c.exe', 'gswin64c.exe', 'gs'};else    bin = {'gs'};endfor a = 1:numel(bin)    path_ = bin{a};    if check_store_gs_path(path_)        return    endend% Search the obvious placesif ispc    default_location = 'C:\Program Files\gs\';    dir_list = dir(default_location);    if isempty(dir_list)        default_location = 'C:\Program Files (x86)\gs\'; % Possible location on 64-bit systems         dir_list = dir(default_location);    end    executable = {'\bin\gswin32c.exe', '\bin\gswin64c.exe'};    ver_num = 0;    % If there are multiple versions, use the newest    for a = 1:numel(dir_list)        ver_num2 = sscanf(dir_list(a).name, 'gs%g');        if ~isempty(ver_num2) && ver_num2 > ver_num            for b = 1:numel(executable)                path2 = [default_location dir_list(a).name executable{b}];                if exist(path2, 'file') == 2                    path_ = path2;                    ver_num = ver_num2;                end            end        end    end    if check_store_gs_path(path_)        return    endelse    bin = {'/usr/bin/gs', '/usr/local/bin/gs'};    for a = 1:numel(bin)        path_ = bin{a};        if check_store_gs_path(path_)            return        end    endend% Ask the user to enter the pathwhile 1    if strncmp(computer, 'MAC', 3) % Is a Mac        % Give separate warning as the uigetdir dialogue box doesn't have a        % title        uiwait(warndlg('Ghostscript not found. Please locate the program.'))    end    base = uigetdir('/', 'Ghostcript not found. Please locate the program.');    if isequal(base, 0)        % User hit cancel or closed window        break;    end    base = [base filesep];    bin_dir = {'', ['bin' filesep], ['lib' filesep]};    for a = 1:numel(bin_dir)        for b = 1:numel(bin)            path_ = [base bin_dir{a} bin{b}];            if exist(path_, 'file') == 2                if check_store_gs_path(path_)                    return                end            end        end    endenderror('Ghostscript not found. Have you installed it from www.ghostscript.com?');function good = check_store_gs_path(path_)% Check the path is validgood = check_gs_path(path_);if ~good    returnend% Update the current default path to the path foundif ~user_string('ghostscript', path_)    warning('Path to ghostscript installation could not be saved. Enter it manually in ghostscript.txt.');    returnendreturnfunction good = check_gs_path(path_)% Check the path is valid[good, message] = system(sprintf('"%s" -h', path_));good = good == 0;return


好了, 这样,就可以运行啦。。

 

但是奇怪的是, 我从官网下载的代码里面,文件夹pmtksupportCopy是空的, 我之前下载的pmtksupportCopy确是有东西的, 下载下来的,直接就可以运行了。 嘿嘿