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

在Cpanel环境中安装mysqlclient失败的问题求助

解决Cpanel环境安装mysqlclient时gcc权限拒绝的问题

问题描述

在Cpanel中安装mysqlclient(版本2.2.0)时,构建wheel失败,核心错误为执行/bin/gcc时权限被拒绝,完整报错信息如下:

Collecting mysqlclient
Using cached mysqlclient-2.2.0.tar.gz (89 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (pyproject.toml) ... error
error: subprocess-exited-with-error

× Building wheel for mysqlclient (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [43 lines of output]
Trying pkg-config --exists mysqlclient
Command 'pkg-config --exists mysqlclient' returned non-zero exit status 1.
Trying pkg-config --exists mariadb
# Options for building extention module:
extra_compile_args: ['-I/usr/include/mysql', '-std=c99']
extra_link_args: ['-lmariadb', '-pthread', '-lz', '-ldl', '-lm', '-lpthread', '-lssl', '-lcrypto']
define_macros: [('version_info', (2, 2, 0, 'final', 0)), ('__version__', '2.2.0')]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-cpython-39
creating build/lib.linux-x86_64-cpython-39/MySQLdb
copying src/MySQLdb/times.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
copying src/MySQLdb/_exceptions.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
copying src/MySQLdb/release.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
copying src/MySQLdb/converters.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
copying src/MySQLdb/connections.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
copying src/MySQLdb/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
copying src/MySQLdb/cursors.py -> build/lib.linux-x86_64-cpython-39/MySQLdb
creating build/lib.linux-x86_64-cpython-39/MySQLdb/constants
copying src/MySQLdb/constants/ER.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
copying src/MySQLdb/constants/CR.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
copying src/MySQLdb/constants/FLAG.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
copying src/MySQLdb/constants/FIELD_TYPE.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
copying src/MySQLdb/constants/__init__.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
copying src/MySQLdb/constants/CLIENT.py -> build/lib.linux-x86_64-cpython-39/MySQLdb/constants
running egg_info
writing src/mysqlclient.egg-info/PKG-INFO
writing dependency_links to src/mysqlclient.egg-info/dependency_links.txt
writing top-level names to src/mysqlclient.egg-info/top_level.txt
reading manifest file 'src/mysqlclient.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
adding license file 'LICENSE'
writing manifest file 'src/mysqlclient.egg-info/SOURCES.txt'
copying src/MySQLdb/_mysql.c -> build/lib.linux-x86_64-cpython-39/MySQLdb
running build_ext
building 'MySQLdb._mysql' extension
creating build/temp.linux-x86_64-cpython-39
creating build/temp.linux-x86_64-cpython-39/src
creating build/temp.linux-x86_64-cpython-39/src/MySQLdb
gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -D_GNU_SOURCE -fPIC -fwrapv -O2 -pthread -Wno-unused-result -Wsign-compare -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -D_GNU_SOURCE -fPIC -fwrapv -D_GNU_SOURCE -fPIC -fwrapv -O2 -pthread -Wno-unused-result -Wsign-compare -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -D_GNU_SOURCE -fPIC -fwrapv -O2 -pthread -Wno-unused-result -Wsign-compare -g -std=c99 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Werror=implicit-function-declaration -fPIC "-Dversion_info=(2, 2, 0, 'final', 0)" -D__version__=2.2.0 -I/home7/pahadisa/virtualenv/notice_board_project/3.9/include -I/opt/alt/python39/include/python3.9 -c src/MySQLdb/_mysql.c -o build/temp.linux-x86_64-cpython-39/src/MySQLdb/_mysql.o -I/usr/include/mysql -std=c99
error: command '/bin/gcc' failed: Permission denied
[end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects

解决方案

1. 安装预编译二进制包(优先推荐)

Cpanel共享主机通常限制用户使用系统级gcc编译代码,直接安装预编译的wheel包可以跳过编译步骤:

pip install mysqlclient --only-binary :all:

如果需要指定版本:

pip install mysqlclient==2.2.0 --only-binary :all:

2. 使用用户级gcc工具(如果可用)

部分主机商会为用户提供专属的gcc工具,先检查当前用户路径下是否有可用gcc:

which gcc

如果返回类似~/opt/bin/gcc的路径,临时指定CC环境变量后再安装:

CC=~/opt/bin/gcc pip install mysqlclient

3. 联系主机商申请权限

如果上述方法都无效,说明主机商完全限制了编译权限,只能联系客服申请开启用户级编译权限,或者让运维人员协助将mysqlclient安装到你的虚拟环境中。

内容的提问来源于stack exchange,提问作者Prabhat Ghimire

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.07 09:06:02