Namecheap cPanel部署Python应用时pip安装numpy失败求助
在Namecheap cPanel中安装Numpy失败的问题解决
问题描述
我在Namecheap的cPanel中创建了一个Python应用,将服务端文件上传至对应目录、UI文件上传至public_html后,出现了500内部服务器错误。联系客服后,按指引安装了joblib,随后从根目录的stderr.log文件中发现缺少numpy组件。但执行pip install numpy时出现构建wheel失败的错误,具体报错包含Cython导入异常、subprocess调用失败等,客服也未能提供解决方案。
报错信息
Building wheels for collected packages: numpy Building wheel for numpy (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for numpy (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [61 lines of output] Running from numpy source directory. setup.py:67: DeprecationWarning: `numpy.distutils` is deprecated since NumPy 1.23.0, as a result of the deprecation of `distutils` itself. It will be removed for Python >= 3.12. For older Python versions it will remain present. It is recommended to use `setuptools < 60.0` for those Python versions. For more details, see: https://numpy.org/devdocs/reference/distutils_status_migration.html import numpy.distutils.command.sdist Traceback (most recent call last): File "/opt/alt/python39/lib64/python3.9/runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "/opt/alt/python39/lib64/python3.9/runpy.py", line 87, in _run_code exec(code, run_globals) File "/tmp/pip-build-env-r6jq5if_/overlay/lib64/python3.9/site-packages/cython.py", line 16, in <module> from Cython.Compiler.Main import main File "/tmp/pip-build-env-r6jq5if_/overlay/lib64/python3.9/site-packages/Cython/Compiler/Main.py", line 28, in <module> from .Scanning import PyrexScanner, FileSourceDescriptor ImportError: /tmp/pip-build-env-r6jq5if_/overlay/lib64/python3.9/site-packages/Cython/Compiler/Scanning.cpython-39-x86_64-linux-gnu.so: failed to map segment from shared object: Operation not permitted Processing numpy/random/_bounded_integers.pxd.in Processing numpy/random/_pcg64.pyx Traceback (most recent call last): File "/tmp/pip-install-q0hfnoqk/numpy_6a92dfb088184f0aaac1f9f1f3acc80e/tools/cythonize.py", line 205, in <module> main() File "/tmp/pip-install-q0hfnoqk/numpy_6a92dfb088184f0aaac1f9f1f3acc80e/tools/cythonize.py", line 201, in main find_process_files(root_dir) File "/tmp/pip-install-q0hfnoqk/numpy_6a92dfb088184f0aaac1f9f1f3acc80e/tools/cythonize.py", line 192, in find_process_files process(root_dir, fromfile, tofile, function, hash_db) File "/tmp/pip-install-q0hfnoqk/numpy_6a92dfb088184f0aaac1f9f1f3acc80e/tools/cythonize.py", line 158, in process processor_function(fromfile, tofile) File "/tmp/pip-install-q0hfnoqk/numpy_6a92dfb088184f0aaac1f9f1f3acc80e/tools/cythonize.py", line 47, in process_pyx subprocess.check_call( File "/opt/alt/python39/lib64/python3.9/subprocess.py", line 373, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/home/nahiuzfc/virtualenv/classify_image/3.9/bin/python3.9_bin', '-m', 'cython', '-3', '--fast-fail', '-o', '_pcg64.c', '_pcg64.pyx']' returned non-zeroexit status 1. Cythonizing sources Traceback (most recent call last): File "/home/nahiuzfc/virtualenv/classify_image/3.9/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module> main() File "/home/nahiuzfc/virtualenv/classify_image/3.9/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main json_out['return_val'] = hook(**hook_input['kwargs']) File "/home/nahiuzfc/virtualenv/classify_image/3.9/lib/python3.9/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 251, in build_wheel return _build_backend().build_wheel(wheel_directory, config_settings, File "/tmp/pip-build-env-r6jq5if_/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 230, in build_wheel return self._build_with_temp_dir(['bdist_wheel'], '.whl', File "/tmp/pip-build-env-r6jq5if_/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 215, in _build_with_temp_dir self.run_setup() File "/tmp/pip-build-env-r6jq5if_/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 267, in run_setup super(_BuildMetaLegacyBackend, File "/tmp/pip-build-env-r6jq5if_/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 158, in run_setup exec(compile(code, __file__, 'exec'), locals()) File "setup.py", line 479, in <module> setup_package() File "setup.py", line 458, in setup_package generate_cython() File "setup.py", line 261, in generate_cython raise RuntimeError("Running cythonize failed!") RuntimeError: Running cythonize failed! [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for numpy Failed to build numpy ERROR: Could not build wheels for numpy, which is required to install pyproject.toml-based projects
解决方法
1. 强制使用预编译wheel包安装
Namecheap共享主机的/tmp目录通常启用了noexec权限,无法运行编译生成的临时共享对象,导致Cython编译失败。直接使用预编译的二进制wheel包跳过编译环节:
pip install numpy --only-binary :all:
2. 指定兼容的Numpy版本
如果最新版本仍有问题,安装适配Python 3.9的稳定预编译版本:
pip install numpy==1.26.4 --only-binary :all:
(1.26.x系列是Python 3.9支持的最后一个Numpy大版本,预编译资源齐全)
3. 确认虚拟环境激活状态
执行安装命令前,必须激活cPanel创建的Python虚拟环境,避免使用系统全局Python导致环境冲突:
source /home/nahiuzfc/virtualenv/classify_image/3.9/bin/activate
4. 自定义临时目录(可选)
如果必须编译安装,可在用户目录下创建自定义临时目录并指定给pip,绕开系统tmp的权限限制:
mkdir -p ~/tmp export TMPDIR=~/tmp pip install numpy
内容的提问来源于stack exchange,提问作者Ishrat Hossain
相关产品推荐
相关产品推荐

