从今天开始,Emacs里面可以运行任何你想要的程序 (Linux & Windows & Mac & BSD)

sudo -H proxychains4 python -m pip install pymupdf==1.14.21

我用了较低版本后,安装成功了。 但是现在eaf-open-browser打开baidu.com仍然报错,仍然没有什么详细错误日志可看

下面是我重新运行了一次安装命令,用于检查:

$ sudo -H proxychains4 python -m pip install dbus-python python-xlib pyqt5 pyqtwebengine pymupdf grip qrcode feedparser
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.12
[proxychains] DLL init: proxychains-ng 4.12
Requirement already satisfied: dbus-python in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: python-xlib in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: pyqt5 in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: pyqtwebengine in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: pymupdf in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: grip in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: qrcode in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: feedparser in /usr/local/lib/python3.6/dist-packages
Requirement already satisfied: six>=1.10.0 in /usr/lib/python3/dist-packages (from python-xlib)
Requirement already satisfied: PyQt5-sip<13,>=12.7 in /usr/local/lib/python3.6/dist-packages (from pyqt5)
Requirement already satisfied: Flask>=0.10.1 in /usr/local/lib/python3.6/dist-packages (from grip)
Requirement already satisfied: docopt>=0.4.0 in /usr/local/lib/python3.6/dist-packages (from grip)
Requirement already satisfied: requests>=2.4.1 in /usr/local/lib/python3.6/dist-packages (from grip)
Requirement already satisfied: Pygments>=1.6 in /usr/local/lib/python3.6/dist-packages (from grip)
Requirement already satisfied: path-and-address>=2.0.1 in /usr/local/lib/python3.6/dist-packages (from grip)
Requirement already satisfied: Markdown>=2.5.1 in /usr/local/lib/python3.6/dist-packages (from grip)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10.1->grip)
Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10.1->grip)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10.1->grip)
Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python3.6/dist-packages (from Flask>=0.10.1->grip)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/lib/python3/dist-packages (from requests>=2.4.1->grip)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3/dist-packages (from requests>=2.4.1->grip)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3/dist-packages (from requests>=2.4.1->grip)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/lib/python3/dist-packages (from requests>=2.4.1->grip)
Requirement already satisfied: setuptools>=36 in /usr/lib/python3/dist-packages (from Markdown>=2.5.1->grip)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3/dist-packages (from Jinja2>=2.10.1->Flask>=0.10.1->grip)

你崩溃的情况我无法重现,比较有效的调试方法就是在 eaf.py, core/browser.py, app/browser/buffer.py 三个文件中加上 print("******") 的代码,然后反复运行,查看 *eaf* buffer 的输出,可以暴力判定哪一行代码有问题,这样可以比较快速的修复问题。

我倒,我昨天还把log打到文件里面查coredump

class AppBuffer(BrowserBuffer):
    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict):
        print("AppBuffer init 1")
        BrowserBuffer.__init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, False, QColor(255, 255, 255, 255))
        print("AppBuffer init 2")

上面的代码加了两行日志,崩溃的时候,eaf只显示了 “ApBuffer init 1”, 所以应该是BrowserBuffer__init__中有问题

class BrowserBuffer(Buffer):

    get_focus_text = QtCore.pyqtSignal(str, str)

    def __init__(self, buffer_id, url, config_dir, arguments, emacs_var_dict, fit_to_view, background_color):

        Buffer.__init__(self, buffer_id, url, arguments, emacs_var_dict, fit_to_view, background_color)
        print("BrowserBuffer init 1")
        self.add_widget(BrowserView(config_dir))
        print("BrowserBuffer init 2")

这段只打印了BrowserBuffer init 1, 所以问题应该在self.add_widget(BrowserView(config_dir))

class BrowserView(QWebEngineView):

    open_url_in_new_tab = QtCore.pyqtSignal(str)
    open_url_in_background_tab = QtCore.pyqtSignal(str)
    translate_selected_text = QtCore.pyqtSignal(str)

    def __init__(self, config_dir):

        super(QWebEngineView, self).__init__()

        self.installEventFilter(self)
        self.config_dir = config_dir
        print("BrowserView init 1")
        self.web_page = BrowserPage()
        print("BrowserView init 2")

这段只打印了BrowserView init 1,所以BrowserPage对象构造的时候出了问题

class BrowserPage(QWebEnginePage):
    def __init__(self):
        print("BrowserPage init 1")
        QWebEnginePage.__init__(self)
        print("BrowserPage init 2")

QWebEnginePage.init(self) 这行有问题。追踪到此,难道还是QT的问题么? 我对pyQT不熟悉,有什么一个简单的程序,可以运行诊断这个问题?

看着你的日志分析,非常像PyQt或者系统Qt的问题,应该和EAF无关。

是啊,现在要找个最简单的PyQt程序运行一下看看

可以Google一个最简单的PyQt5 Browser Demo测试一下。

创建t.py测试程序, 代码如下:

import sys

from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication

app = QApplication(sys.argv)

web = QWebEngineView()
web.load(QUrl("https://further-reading.net"))
web.show()

sys.exit(app.exec_())

python3-dbg t.py

Traceback (most recent call last):
  File "t.py", line 3, in <module>
    from PyQt5.QtCore import *
ImportError: /usr/local/lib/python3.6/dist-packages/PyQt5/QtCore.abi3.so: undefined symbol: PyModule_Create2
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
    from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
    from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
    import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
    from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
    import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "t.py", line 3, in <module>
    from PyQt5.QtCore import *
ImportError: /usr/local/lib/python3.6/dist-packages/PyQt5/QtCore.abi3.so: undefined symbol: PyModule_Create2

还没有找到解决办法

把用apt安装的 pyqt删除, 用 pip3 安装试试

你是将pip3软链接到了pip吗?不是的话,用pip3重新安装所有依赖试一下。我之前也遇到和你类似的问题:默认python是py3,我就认为pip安装的也是对应py3的。然后换成pip3就可以用了。

我是直接建了一个 virtualenv, 把 eaf-python-command 指向 env 下的python执行文件 ,把所有库都安装到 env 里面。目前用着还行。

在github或者gitee上分享一下你的virtualenv吧,折腾死了。

$ sudo apt list --installed | grep pyqt

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

之前就清理过一次

反其道而之,不采用pip install, 将所有sudo pip install 和 pip install的package卸载掉,然后只采用ubuntu18.04 apt提供的pyqt包。现在程序可以运行。但碰到一个问题,下面的程序在spacemacs的shell里面只能用sudo才能运行。

import sys

from PyQt5.QtCore import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication

app = QApplication(sys.argv)

web = QWebEngineView()
web.load(QUrl("https://www.baidu.com"))
web.show()

sys.exit(app.exec_())

如果不用sudo运行,就会报错

Qt: Session management error: Could not open network socket
[1:1:0202/170712.758765:FATAL:sandbox_linux.cc(180)] Check failed: sandbox::Credentials::MoveToNewUserNS(). 
#0 0x7fdb947dfaee <unknown>
#1 0x7fdb947f20e2 <unknown>
#2 0x7fdb944ede60 <unknown>
#3 0x7fdb94033fe0 <unknown>
#4 0x7fdb947be6d7 <unknown>
#5 0x7fdb947bedf7 <unknown>
#6 0x7fdb947b81c9 <unknown>
#7 0x7fdb93e68b59 QtWebEngine::processMain()
#8 0x5641b40efbf3 <unknown>
#9 0x7fdb928d1b97 __libc_start_main
#10 0x5641b40efc7a <unknown>

现在 eaf 中看到的也是这个错误。

如果直接在终端窗口里面运行上面的pyqt程序,正常,不需要sudo也可以运行。 但是一旦在spacemacs的shell中运行 python t.py 就会出现错误。错误如上所述。

现在咋办,难道emacs启动用sudo, 也太奇怪了吧。

终于搞定了!!

原因是.spacemacs.d/.spacemacs.env文件里面保留了proxychains4的环境变量,居然导致spacemacs启动的时候会自动使用proxychains4翻墙。 而proxychains4会导致pyqt程序崩溃,包括chromium-browser程序启动也会崩溃。 删除掉.env文件后正常了。

@manateelazycat 今天试着更为深度的集成 eaf, 感觉挺好用,贴出来大家讨论讨论

  (defun eh-eaf-open (path &optional _linkstr)
    (if (and (string-equal system-type "gnu/linux")
             (functionp 'eaf-open)
             (not (file-directory-p path)))
        (funcall 'eaf-open path)
      (eh-system-open path)))

  (defun eh-system-open (path &optional _linkstr)
    (cond ((string-equal system-type "windows-nt")
           (w32-shell-execute "open" path))
          ((string-equal system-type "darwin")
           (concat "open " (shell-quote-argument path)))
          ((string-equal system-type "gnu/linux")
           (let ((process-connection-type nil))
             (start-process "" nil "xdg-open" path)))))

  (defun eh-find-file (orig-fun &rest args)
    (let ((filename (car args))
          (cmd (symbol-name this-command)))
      (cond ((cl-find-if
              (lambda (regexp)
                (string-match regexp filename))
              '("\\.pdf\\'" "\\.png\\'" "\\.jpe?g\\'" "\\.bmp\\'" "\\.gif\\'"))
             (eh-eaf-open filename))
            ((cl-find-if
              (lambda (regexp)
                (string-match regexp filename))
              '("\\.docx?\\'" "\\.xlsx?\\'" "\\.pptx?\\'" "\\.wps?\\'"))
             (eh-system-open filename))
            ((and (or (string-match "^org-" cmd)
                      (string-match "^eh-org-" cmd))
                  (file-directory-p filename))
             (eh-system-open filename))
            (t (apply orig-fun args)))))

  (dolist (f '(find-file
               find-file-read-only
               find-file-other-window
               find-file-other-frame
               org-open-file))
    (advice-add f :around 'eh-find-file))
1 个赞

不知EAF的pdf阅读器能像pdf-tools一样和org-noter配合使用吗?

我不用org,主要嫌麻烦,欢迎patch

不知愿意分享一下对知识的管理? 我觉得 org 是最简单的办法. 如果不去系统管理知识,很多知识都用不上.

Ref:

Reif, F., 2008. How can we help students acquire effectively usable physics knowledge? 179, 179–196. How can we help students acquire effectively usable physics knowledge? | AIP Conference Proceedings | AIP Publishing

知识不在于记录管理,而在于频繁使用。

知识多并不等于智慧,智慧源于安静和思考。

很久以前我也到处记知识,现在我基本上不记了。

9 个赞