You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Emacs运行Jupyter-run-repl提示ZMQ模块未找到的解决方法求助

解决Emacs中Jupyter-run-repl报“ZMQ module not found”错误

问题说明

已安装Jupyter内核,conda环境中的ZMQ在终端可正常使用,Emacs也配置了对应环境路径,但运行jupyter-run-repl时仍提示“ZMQ module not found”错误。

当前配置代码

路径配置

(setq python-shell-interpreter "/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/bin/python")
(setq python-shell-interpreter-args "")

(setq jupyter-runtime-directory "/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/share/jupyter/runtime/")
(setq jupyter-command "/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/bin/jupyter")

(add-to-list 'exec-path "/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/bin")
(setenv "PATH" (concat "/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/bin:" (getenv "PATH")))

Emacs功能配置

* Jupyter REPL Integration
   #+begin_src emacs-lisp
     (use-package jupyter
       :straight t)

     (use-package python-mode
       :straight t
       :hook (python-mode . jupyter-run-repl)
       :config
       (defun my-python-send-region ()
         "Send selected region or current line to Jupyter REPL."
         (interactive)
         (if (use-region-p)
             (jupyter-repl-send-region (region-beginning) (region-end))
           (jupyter-repl-send-line)))

       (define-key python-mode-map (kbd "S-<return>") 'my-python-send-region))

     (straight-use-package
      '(zmq
        :type git
        :host github
        :repo "nnicandro/emacs-zmq"))
     (straight-use-package 'jupyter)

   #+end_src

* Jupyter Org Mode Client
   #+begin_src emacs-lisp
   (use-package jupyter-org-client
     :straight jupyter
     :after (org jupyter)
     :config
     (setq org-babel-default-header-args:jupyter-python '((:async . "yes") (:session . "py") (:kernel . "python3"))))
   #+end_src

解决方法

  • 从conda环境启动Emacs:终端中先激活目标conda环境,再启动Emacs,确保Emacs继承正确的环境依赖:
    conda activate emacs-py && emacs
    
  • 重新编译emacs-zmq包:emacs-zmq依赖系统级ZMQ库,可能存在编译链接问题。先删除已安装的包,再重新安装编译:
    1. 执行M-x straight-delete-package RET zmq RET删除现有包
    2. 执行M-x straight-use-package RET zmq RET重新安装编译
  • 指定Jupyter内核的Python路径:修改Jupyter内核配置文件,确保内核使用目标conda环境的Python。路径通常为/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/share/jupyter/kernels/python3/kernel.json,修改内容如下:
    {
     "argv": [
      "/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/bin/python",
      "-m",
      "ipykernel_launcher",
      "-f",
      "{connection_file}"
     ],
     "display_name": "Python 3 (emacs-py)",
     "language": "python"
    }
    
  • 设置PYTHONPATH环境变量:在Emacs配置中添加PYTHONPATH,确保能找到conda环境的依赖包:
    ;; 替换python3.x为环境中实际的Python版本号
    (setenv "PYTHONPATH" (concat "/opt/homebrew/Caskroom/miniconda/base/envs/emacs-py/lib/python3.x/site-packages:" (getenv "PYTHONPATH")))
    

内容的提问来源于stack exchange,提问作者Nathan Drake

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 00:02:41