使用Python 3部署到Ubuntu服务器并安装awsebcli失败

43次阅读
没有评论

问题描述

之前在AWS ElasticBeanstalk上的持续部署一直正常运行,但突然之间出现了以下错误:

$ pip install awsebcli -q --upgrade
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
$ eb deploy production
Traceback (most recent call last):
  File "/usr/local/bin/eb", line 5, in <module>
    from ebcli.core.ebcore import main
  File "/usr/local/lib/python2.7/dist-packages/ebcli/core/ebcore.py", line 19, in <module>
    from ebcli.core import ebglobals, base, hooks
  File "/usr/local/lib/python2.7/dist-packages/ebcli/core/hooks.py", line 20, in <module>
    from ebcli.core import fileoperations
  File "/usr/local/lib/python2.7/dist-packages/ebcli/core/fileoperations.py", line 32, in <module>
    from json import load, JSONDecodeError
ImportError: cannot import name JSONDecodeError

初始部署脚本假设使用的是Python 2.7版本以及awsebcli的安装。以下是脚本的代码片段:

- apt-get update -y
- curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
- python get-pip.py
- pip --version
- pip install --upgrade pip setuptools
- pip install awsebcli -q --upgrade
- eb deploy production

但在出现错误后,用户决定切换到Python 3并安装pip3。以下是更新后的脚本及其输出:

- apt-get update -y
- apt-get install -y python3-pip
- update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
- update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2
- update-alternatives --list python
- python --version
- pip3 --version
- pip3 install awsebcli -q --upgrade
- eb deploy production
$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.5
$ python --version
Python 3.5.3
$ pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
$ pip3 install awsebcli -q --upgrade
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-0a4fa4ab/awsebcli/

用户尝试了多种方法,但是在部署时仍然遇到退出码1的问题。他希望能够得到一些建议来解决这个问题。

解决方案

方案1:更新Python版本

根据用户提供的信息,awsebcli 3.20.0 版本要求使用Python版本不小于3.5。你可以通过以下步骤更新Python版本:

  1. 安装Python 3.5或更高版本:

    bash
    $ apt-get install python3.5

  2. 更新Python可选项链接以使用新安装的Python 3.5:

    bash
    $ update-alternatives --install /usr/bin/python python /usr/bin/python3.5 2

  3. 确认Python版本:

    bash
    $ python --version

方案2:手动安装awsebcli

如果使用pip安装awsebcli遇到问题,你可以尝试通过源代码进行手动安装。以下是示例脚本:

$ apt-get update -y
$ apt-get install -y build-essential zlib1g-dev libssl-dev libncurses-dev libffi-dev libsqlite3-dev libreadline-dev libbz2-dev
$ git clone https://github.com/aws/aws-elastic-beanstalk-cli-setup.git
$ ./aws-elastic-beanstalk-cli-setup/scripts/bundled_installer
$ echo 'export PATH="/root/.ebcli-virtual-env/executables:$PATH"' >> ~/.bash_profile && source ~/.bash_profile
$ echo 'export PATH=/root/.pyenv/versions/3.7.2/bin:$PATH' >> /root/.bash_profile && source /root/.bash_profile
$ eb deploy production

请根据你的实际情况进行调整,并确保脚本的路径和文件名正确。

请注意,执行脚本可能需要适当的权限,并且可能会因系统配置和网络访问问题而有所不同。

方案3:查看官方文档和讨论

用户在问题描述中提到了在GitHub上的讨论中找到的一些信息,你可以继续参考那些链接,可能会有其他用户遇到类似问题并给出了解决方案。

结论

在尝试升级Python版本、手动安装awsebcli或查阅官方文档和讨论之后,你应该能够解决部署问题。记得在操作过程中做好备份,并根据实际情况进行调整。如果问题持续存在,你可以进一步在相关的技术社区或论坛上寻求帮助。

正文完