自行编译MAGE后启动Memgraph时Python模块依赖缺失
我执行以下命令从MAGE仓库(main分支)编译安装了模块:
python3 setup build -p /usr/lib/memgraph/query_modules
但启动Memgraph时,大量模块因Python依赖缺失无法加载,部分错误示例如下:
[2023-09-18 07:53:41.206] [memgraph_log] [error] Unable to load module "/usr/lib/memgraph/query_modules/migrate.py"; Traceback (most recent call last):
File "/usr/lib/memgraph/query_modules/migrate.py", line 3, in
import mysql.connector as mysql_connector
ModuleNotFoundError: No module named 'mysql'
...(其他类似依赖缺失错误)
解决步骤:
安装所有缺失的依赖包:
执行以下pip命令一次性安装所有报错中提到的依赖:pip3 install mysql-connector-python python-igraph defusedxml networkx numpy gqlalchemy gensim torch tqdm gekko elasticsearch scikit-learn如果Memgraph运行在系统级Python环境,可能需要添加
sudo以确保依赖安装到系统路径:sudo pip3 install mysql-connector-python python-igraph defusedxml networkx numpy gqlalchemy gensim torch tqdm gekko elasticsearch scikit-learn验证Python环境一致性:
确保安装依赖的Python环境与Memgraph使用的Python环境一致。可以通过Memgraph日志中的Python路径确认,或者直接使用Memgraph关联的Python解释器执行pip安装。重启Memgraph服务:
依赖安装完成后,重启Memgraph使模块加载生效:sudo systemctl restart memgraph
说明
MAGE包含多个功能模块,不同模块依赖不同的第三方Python库。默认安装流程不会自动安装所有可选依赖,因此需要根据报错信息手动补全缺失的库。
内容的提问来源于stack exchange,提问作者Sven Martoen

