在 Ubuntu 中从 PPA 安装 PHP5.6 时出现 UnicodeDecodeError

在 Ubuntu 中从 PPA 安装 PHP5.6 时出现 UnicodeDecodeError

我有一个干净的 VPS,装有 Ubuntu 14.04 LTS x64。并尝试了以下操作:

# Upgrade The Base Packages

apt-get update
apt-get upgrade -y

# Add A Few PPAs To Stay Current

apt-get install -y software-properties-common

apt-add-repository ppa:nginx/stable -y
apt-add-repository ppa:rwky/redis -y
apt-add-repository ppa:chris-lea/node.js -y
apt-add-repository ppa:ondrej/php5-5.6 -y

但最后一个却失败了:

root@xxx:~# apt-add-repository ppa:ondrej/php5-5.6 -y

gpg: keyring `/tmp/tmp9jdzm9kw/secring.gpg' created
gpg: keyring `/tmp/tmp9jdzm9kw/pubring.gpg' created
gpg: requesting key E5267A6C from hkp server keyserver.ubuntu.com
gpg: /tmp/tmp9jdzm9kw/trustdb.gpg: trustdb created
gpg: key E5267A6C: public key "Launchpad PPA for Ond\xc5\x99ej Sur�" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 687, in addkey_func
    func(**kwargs)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 370, in add_key
    return apsk.add_ppa_signing_key()
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 261, in add_ppa_signing_key
    tmp_export_keyring, signing_key_fingerprint, tmp_keyring_dir):
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 210, in _verify_fingerprint
    got_fingerprints = self._get_fingerprints(keyring, keyring_dir)
  File "/usr/lib/python3/dist-packages/softwareproperties/ppa.py", line 202, in _get_fingerprints
    output = subprocess.check_output(cmd, universal_newlines=True)
  File "/usr/lib/python3.4/subprocess.py", line 605, in check_output
    output, unused_err = process.communicate(inputdata, timeout=timeout)
  File "/usr/lib/python3.4/subprocess.py", line 936, in communicate
    stdout = _eintr_retry_call(self.stdout.read)
  File "/usr/lib/python3.4/subprocess.py", line 487, in _eintr_retry_call
    return func(*args)
  File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 92: ordinal not in range(128)

我不知道哪里出了问题。一切都很基础。

答案1

正确的方法是在终端中启用 UTF-8 支持。

首先检查你的语言环境:

locale -a

然后,安装一个UTF-8的语言环境,针对en_US,示例如下:

locale-gen en_US.UTF-8

然后您需要导出它:

export LANG=en_US.UTF-8

那么该add-apt-repository命令就能正常工作。

如果这仍然不起作用,请尝试使用此行:

LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:ondrej/php

答案2

我遇到了同样的问题。我认为错误是由于名称中的非西方字符 (Ond\xc5\x99ej Sur�) 造成的。

确保您已删除 php5。

您可以手动添加存储库:

# echo "deb http://ppa.launchpad.net/ondrej/php5-5.6/ubuntu trusty main" > /etc/apt/sources.list.d/ondrej-php5-5_6-trusty.list

# apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C

# apt-get install php5

使用 php -v 检查是否安装了 5.6:

# php -v
PHP 5.6.6-1+deb.sury.org~trusty+1 (cli) (built: Feb 20 2015 11:22:10) 

答案3

尝试安装语言包,这可能会纠正你的编码问题,例如

sudo apt-get install language-pack-en

这将为所有受支持的软件包(包括 Python)提供英语翻译数据更新。

看:UnicodeEncodeError:'ascii'编解码器无法编码字符

答案4

请尝试以下操作:

  • 如果您已经安装了 php5,请删除。

  • 现在尝试全新安装。

  • 运行gedit /etc/apt/sources.list添加如下代码:

    deb http://ppa.launchpad.net/ondrej/php5-5.6/ubuntu trusty main 
    deb-src http://ppa.launchpad.net/ondrej/php5-5.6/ubuntu trusty main
    

    请小心编辑和添加源代码。

  • 保存并更新。(1234)

    sudo apt-get update  
    
  • 现在尝试安装 php5。

安装后你应该得到 php5-5.6。

相关内容