debugging “错误:无法打开加载文件:没有这样的文件或目录,编译时使用-package”

daupos2t  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(143)

当我对init.el进行字节编译时,我得到了下面的错误消息。
--batch -f批处理字节编译init.el
在顶级表单中:初始化EL:12:1:错误:无法打开加载文件:没有这样的文件或目录,请使用包
这是我的init. el。

(require 'package)

(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)
(setq package-user-dir (expand-file-name "elpa" user-emacs-directory))
(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(require 'use-package)

为什么会出现此错误?如何修复?
环境信息

➤ emacs --version
GNU Emacs 28.1
Copyright (C) 2022 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.

操作系统:MacOS Big Sur

6mw9ycah

6mw9ycah1#

我也在一台使用相同版本Emacs的Mac电脑上,在字节编译启动文件时遇到了类似的问题。我发现在命令行--batch byte编译时,加载路径不包括任何包目录。使用下面的代码作为倒数第二个init.el节的等价物,克服了导致我来到这里的错误,希望在某种程度上不受未来变化的影响。

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package)
  (eval-when-compile
    (unless (bound-and-true-p package--initialized)
      (package-initialize))  ;; be sure load-path includes package directories
    (require 'use-package)
    ))

相关问题