JupyterLab使用SQLAlchemy访问MySQL时出现以下错误:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[7], line 2
1 from sqlalchemy import create_engine
----> 2 engine = create_engine("mysql://scrat:scrat%40123@127.0.0.1/scrat")

File <string>:2, in create_engine(url, **kwargs)

File ~/frin/python/venvs/jupyter/lib/python3.12/site-packages/sqlalchemy/util/deprecations.py:281, in deprecated_params.<locals>.decorate.<locals>.warned(fn, *args, **kwargs)
274 if m in kwargs:
275 _warn_with_version(
276 messages[m],
277 versions[m],
278 version_warnings[m],
279 stacklevel=3,
280 )
--> 281 return fn(*args, **kwargs)

File ~/frin/python/venvs/jupyter/lib/python3.12/site-packages/sqlalchemy/engine/create.py:599, in create_engine(url, **kwargs)
597 if k in kwargs:
598 dbapi_args[k] = pop_kwarg(k)
--> 599 dbapi = dbapi_meth(**dbapi_args)
601 dialect_args["dbapi"] = dbapi
603 dialect_args.setdefault("compiler_linting", compiler.NO_LINTING)

File ~/frin/python/venvs/jupyter/lib/python3.12/site-packages/sqlalchemy/dialects/mysql/mysqldb.py:147, in MySQLDialect_mysqldb.import_dbapi(cls)
145 @classmethod
146 def import_dbapi(cls):
--> 147 return __import__("MySQLdb")

ModuleNotFoundError: No module named 'MySQLdb'

这是因为SQLAlchemy连接MySQL默认驱动是MySQLdb,MySQLdb仅支持Python2,不支持Python3。如果使用Python3,可以安装pymysql库,并将连接串改为mysql+pymysql://scrat:scrat%40123@127.0.0.1/scrat就好了。

因系统自带的Python版本较低,因此安装最新稳定版Python3.12.2。安装完成后增加配置如下:

1
(setq python-shell-interpreter "python3.12")

在Emacs内置Python-mode下启动Python解释器时(C-c C-p)提示以下告警信息:

1
■  Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native-enable’ was t and "python3.12" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally. Consider installing the python package "readline".

按照提示安装readline后再次启动解释器时出现卡死的情况。目前不清楚具体原因,但这个警告可以直接忽略,对使用无影响。

阅读全文 »

Emacs启用flymake后代码检查未生效,提示如题信息,原因是未安装代码检查器。可以安装Python官方发布的flake8。注意,安装时需要跟Emacs使用的Python解释器相同的位置。如我使用的解释器配置如下:

1
(setq python-shell-interpreter "/opt/python/bin/python3.12")

所以,我的安装命令如下:

1
$ /opt/python/bin/pip3.12 install flake8

再次编辑Python文件后发现可以正常检查语法并正确提示错误了。

阅读全文 »

error: No X toolkit could be found

1
2
3
4
5
6
7
checking for libXaw... configure: error: No X toolkit could be found.
If you are sure you want Emacs compiled without an X toolkit, pass
--with-x-toolkit=no
to configure. Otherwise, install the development libraries for the toolkit
that you want to use (e.g. Gtk+) and re-run configure.

--with-x-toolkit=no

运行以下命令:

1
# apt install libgtk-3-dev

error: The following required libraries were not found

阅读全文 »

异常信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$ sudo apt install elpa-elpy
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
elpa-elpy 已经是最新版 (1.28.0-2)。
下列软件包是自动安装的并且现在不需要了:
clang deepin-clone deepin-pw-check deepin-recovery-tool freeglut3 gir1.2-keybinder-3.0 gir1.2-notify-0.7 gir1.2-vte-2.91 imageworsener jfsutils libbotan-2-9
libbox2d2.3.0 libcppunit-1.14-0 libdumbnet1 libgsl23 libgslcblas0 libkeybinder-3.0-0 libmaxminddb0 libmspack0 libomp5-13 libopencolorio1v5 libqbscore1.12
libqbsqtprofilesetup1.12 libqscintilla2-qt5-13 libqscintilla2-qt5-l10n libqt5designercomponents5 libqt5quicktest5 libqt5serialport5 libqt5webkit5
libqt5xmlpatterns5 libqtermwidget5-0 libquazip5-1 libsmi2ldbl libsunpinyin3v5 libtspi1 libutempter0 libutf8proc2 libvte-2.91-0 libvte-2.91-common
libwireshark-data libwireshark11 libwiretap8 libwscodecs2 libwsutil9 libxmlsec1 libxmlsec1-openssl libyaml-cpp0.6 live-system-com partclone python3-configobj
python3-psutil qbs-common qdoc-qt5 qhelpgenerator-qt5 qmlscene qt3d5-doc qt5-doc qt5.15gles-basic.runtime.szbt qt5.15gles-extra.runtime.szbt
qtattributionsscanner-qt5 qtbase5-doc qtcharts5-doc qtconnectivity5-doc qtcreator-data qtcreator-doc qtdatavisualization5-doc qtdeclarative5-dev-tools
qtdeclarative5-doc qtermwidget5-data qtgamepad5-doc qtgraphicaleffects5-doc qtlocation5-doc qtmultimedia5-doc qtnetworkauth5-doc qtquickcontrols2-5-doc
qtquickcontrols5-doc qtscript5-doc qtscxml5-doc qtsensors5-doc qtserialbus5-doc qtserialport5-doc qtsvg5-doc qttools5-doc qtvirtualkeyboard5-doc
qtwayland5-doc qtwebchannel5-doc qtwebengine5-doc qtwebsockets5-doc qtwebview5-doc qtx11extras5-doc qtxmlpatterns5-dev-tools qtxmlpatterns5-doc
squashfs-tools sunpinyin-data x11-apps x11-session-utils xbitmaps xinit xterm
使用'sudo apt autoremove'来卸载它(它们)。
升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 6 个软件包未被升级。
有 1 个软件包没有被完全安装或卸载。
解压缩后会消耗 0 B 的额外空间。
您希望继续执行吗? [Y/n] y
正在设置 jenkins (2.426.2) ...
Job for jenkins.service failed because the control process exited with error code.
See "systemctl status jenkins.service" and "journalctl -xeu jenkins.service" for details.
invoke-rc.d: initscript jenkins, action "start" failed.
● jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Tue 2024-02-06 16:22:14 CST; 4ms ago
Process: 92410 ExecStart=/usr/bin/jenkins (code=exited, status=1/FAILURE)
Main PID: 92410 (code=exited, status=1/FAILURE)
dpkg: 处理软件包 jenkins (--configure)时出错:
已安装 jenkins 软件包 post-installation 脚本 子进程返回错误状态 1
在处理时有错误发生:
jenkins
needrestart is being skipped since dpkg has failed
E: Sub-process /usr/bin/dpkg returned an error code (1)

解决方法见:dpkg: 处理软件包 xxx (–configure)时出错 解决办法

执行以下命令在刷新安装源后进行安装时提示匹配不到python-mode:

1
2
M-x package-refresh-contents
M-x package-install RET python-mode

这是因为GNU Emacs未包含Melpa源,为了保障效率可以切换至国内镜像源。在 ~/.emacs中添加以下配置:

1
2
3
4
(setq package-archives '(("gnu"    . "http://mirrors.tuna.tsinghua.edu.cn/elpa/gnu/")
("nongnu" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/nongnu/")
("melpa" . "http://mirrors.tuna.tsinghua.edu.cn/elpa/melpa/")))
(package-initialize) ;; You might already have this line

镜像使用参考网址:ELPA 镜像使用帮助

阅读全文 »

执行以下命令修改sudoer文件的权限:

1
pkttyagent -p $(echo $$) | pkexec chmod 7777 /etc/sudoers

修复完语法错误后将sudoer文件的权限复原:

1
pkttyagent -p $(echo $$) | pkexec chmod 0400 /etc/sudoers
0%