“错误:无法打开加载文件:没有这样的文件或目录,使用包装”当我字节编译时

发布于 2025-01-23 10:06:29 字数 970 浏览 0 评论 0原文

当我字节编译我的init.el时,我收到以下错误消息。

➤emacs-batch -f batch-batch-byte-compile init.el

以高级形式: init.el:12:1:错误:无法打开加载文件:没有这样的文件或目录,use-package

,这是我的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.

OS:Macos Big Sur

When I byte compiled my init.el, I got the following error message.

➤ emacs --batch -f batch-byte-compile init.el

In toplevel form:
init.el:12:1: Error: Cannot open load file: No such file or directory, use-package

and this is my 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)

Why did I get the error? How can I fix is?

Environment Info

➤ 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.

OS: macOS Big Sur

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红尘作伴 2025-01-30 10:06:29

我也在具有相同版本的emacs的Mac上,并且遇到了类似的问题字节编译我的启动文件。我发现在命令行 - 批处理字节汇编期间,负载路径不包括任何包装目录。将以下内容作为您的下一init.el stanza的等效物,克服了引导我这里的错误,希望以一种不受未来变化的方式。

(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)
    ))

I too am on a Mac with the same version of Emacs and was having similar problems byte-compiling my startup files. I found that during command line --batch byte compilation the load-path did not include any of the package directories. Using the following as the equivalent of your next to last init.el stanza overcame the errors that led me here, hopefully in a way that is immune to future changes.

(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)
    ))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文