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

Perl的Inline::Python在AlmaLinux 8报错,CentOS 7正常求助

解决Inline::Python调用Braintree API的兼容性问题

问题根源

AlmaLinux 8默认的Python 2.7中,encodebytes是Python 3专属函数,对应Python 2.7的是encodestring。而新版Braintree Python SDK(4.x及以上)已停止支持Python 2.7,导致导入失败;同时Inline::Python默认绑定Python 2.7,和新服务器的Python 3环境脱节。


方案一:修复Python 2.7下的Braintree导入错误

适合临时过渡,保留原有Python 2.7环境:

  • 查看当前Python 2.7环境的Braintree版本:
    pip2 show braintree
    
  • 若版本为4.x及以上,降级到支持Python 2.7的最后一个稳定版(3.101.0):
    pip2 install braintree==3.101.0
    
  • 验证修复:在Python 2.7交互终端执行import braintree,确认无ImportError。

方案二:让Inline::Python绑定Python 3(长期推荐)

彻底摆脱Python 2.7的维护风险:

  1. 安装Python 3开发依赖:
    yum install python3-devel
    
  2. 重新编译安装Inline::Python,指定Python 3路径:
    • 使用cpanm安装:
      cpanm --configure-args="--with-python=/usr/bin/python3" Inline::Python
      
    • 使用cpan shell安装:
      进入cpan终端后执行force install Inline::Python,在配置环节输入Python 3的路径(如/usr/bin/python3)。
  3. 验证绑定结果:在Perl脚本中加入测试代码,运行后确认输出Python 3版本:
    use Inline Python => <<'END';
    import sys
    print(sys.version)
    END
    
  4. 在Python 3环境安装Braintree SDK:
    pip3 install braintree
    

内容的提问来源于stack exchange,提问作者Timothy R. Butler

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 20:25:17