虚拟环境与 emacs

论坛有些非常棒的包需要python, linux系统一般不允许全局安装 于是就要创建一个 venv, activate ,再启动 emacs

问了下AI, 写了个脚本来做这件事


# 激活虚拟环境
source ~/myenv/bin/activate

# 启动 Emacs
emacs & disown

抛砖引玉,不知还有没有更好的办法

archlinux 可以用包管理器来安装 Python 依赖,比如 epc 包在 Arch 中就是 python-epc 。

额,我目前在 Windows 上用 Emacs,用 Beancount 记账时需要激活安装的 Conda 环境,于是用了conda.el 来启动

Conda.el 和 Beancount.el 的配置
  (use-package conda
    :defer 1 ; 设置为 t 时 beancount 函数启动异常
    :custom
    (conda-anaconda-home "d:/Applications/Scoop/apps/miniconda3/current/"))

  (use-package beancount
    :after conda
    :custom
    (beancount-number-alignment-column 60)
    :config
    (conda-env-activate "bean")
    (defun my/beancount-auto-fava ()
      "`beancount-fava` only when open `ledger.beancount`"
      (when (string-equal (file-name-nondirectory buffer-file-name) "Ledger.beancount")
  	(beancount-fava)))
    (defun my/beancount-kill-buffer ()
      (interactive)
      (if (string-equal (file-name-nondirectory buffer-file-name) "Ledger.beancount")
  	  (progn
  	    (beancount-fava)
  	    (when (get-buffer "*fava*")
  	      (kill-buffer "*fava*"))
  	    (kill-buffer (current-buffer)))
  	(kill-buffer (current-buffer)))) ;; 其他文件正常关闭
    :bind
    (:map beancount-mode-map
  	  ("C-x k" . my/beancount-kill-buffer))
    :hook
    (beancount-mode . outline-minor-mode)
    (beancount-mode . my/beancount-auto-fava))

最简单的办法是用 pyvenv pyvenv-auto