在已安装的 MELPA 软件包上调用 (require ...) 时出现 FlyCheck 错误“无法打开加载文件”

Calling (require ...) on a MELPA installed package gives FlyCheck error "Cannot open load file"

提问人:cidra 提问时间:6/16/2022 最后编辑:philscidra 更新时间:7/17/2022 访问量:185

问:

我想通过 MELPA 安装一些软件包,以便我可以访问它们的变量和函数,而不会收到“自由变量”或“未定义函数”警告。require

但是,当我尝试加载包时,Flycheck 找不到它,并且出现“无法打开加载文件”错误。似乎字节码编译器没有读入包含MELPA安装文件的目录,但我不知道如何解决这个问题。

我正在将 Emacs 26.3 与 Purcell 的配置一起使用,其中包括 Flymake-Flycheck。这个片段涵盖了 init-elpa.el 自定义文件的相关部分,您可以在其中看到,即使我安装了软件包,它仍然被 Flycheck 标记为错误。(require ...)

;;; init-elpa.el --- Settings and helpers for package.el -*- lexical-binding: t -*-

(require 'package)
(require 'cl-lib)

;;; Install into separate package dirs for each Emacs version, to prevent bytecode incompatibility
(setq package-user-dir
      (expand-file-name (format "elpa-%s.%s" emacs-major-version emacs-minor-version)
                        user-emacs-directory))

;;; Standard package repositories
(add-to-list 'package-archives '( "melpa" . "https://melpa.org/packages/") t)


(defun require-package (package &optional min-version no-refresh)
  "Install given PACKAGE, optionally requiring MIN-VERSION.
If NO-REFRESH is non-nil, the available package lists will not be
re-downloaded in order to locate PACKAGE."
  ...)

(defun maybe-require-package (package &optional min-version no-refresh)
  "Try to install PACKAGE, and return non-nil if successful.
In the event of failure, return nil and print a warning message.
Optionally require MIN-VERSION.  If NO-REFRESH is non-nil, the
available package lists will not be re-downloaded in order to
locate PACKAGE."
  ...)

;;; Fire up package.el
(setq package-enable-at-startup nil)
(package-initialize)

(defvar sanityinc/required-packages nil)

(defun sanityinc/note-selected-package (oldfun package &rest args)
  "If OLDFUN reports PACKAGE was successfully installed, note that fact.
The package name is noted by adding it to
`sanityinc/required-packages'.  This function is used as an
advice for `require-package', to which ARGS are passed."
  ...)

(advice-add 'require-package :around 'sanityinc/note-selected-package)

(when (fboundp 'package--save-selected-packages)
  (require-package 'seq)
  (add-hook 'after-init-hook
            (lambda ()
              (package--save-selected-packages
               (seq-uniq (append sanityinc/required-packages package-selected-packages))))))


;; READ HERE: now i try to install and require some packages.
(require-package 'fullframe)
(require-package 'evil)
(require 'fullframe) ;; Flycheck gives an ERROR: cannot open load file, files or directory does not exist
(require 'evil) ;; same as above
(require 'python) ;;this gives no error, since it's built-in i guess.

(provide 'init-elpa)
;;; init-elpa.el ends here

您可以看到它被调用,因此应该设置加载路径。此外,我已设置为 ,这应该意味着字节码编译器读取与普通 emacs 实例相同的目录。(package-initialize)flycheck-emacs-lisp-load-path'inherit

我应该怎么做才能使字节码编译器识别我的ELPA目录?

emacs 编译器-warnings flycheck

评论


答:

-1赞 Miao ZhiCheng 7/17/2022 #1

检出变量flycheck-emacs-lisp-load-path

flycheck-emacs-lisp-load-path 是 'flycheck.el' 中定义的变量。 ...当设置为 'inherit' 时,使用当前 Emacs 的 'load-path' 会话。

例如,您可以执行以下操作:

(use-package flycheck
  :diminish ""
  :custom
  (flycheck-emacs-lisp-load-path 'inherit)
...