【问题标题】:How to overcome dependency issues while upgrading Python Requests Module on Amazon Linux Instance (EC2)?如何在 Amazon Linux 实例 (EC2) 上升级 Python 请求模块时克服依赖性问题?
【发布时间】:2018-12-31 23:41:35
【问题描述】:

我有一个简单的 Flask 应用程序,我尝试在我的新 AWS EC2 实例上运行,如下所示:

FLASK_APP=app.py flask run

我收到以下错误:

  File "/home/ec2-user/my-folder/my-app/my-script.py", line 16, in <module>
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
AttributeError: 'module' object has no attribute 'disable_warnings'

我在网上找到的一个建议是升级我的 Python Requests 模块版本。 我当前的版本是 1.2.3。

当我尝试升级它时会发生以下情况:

[ec2-user@ip-xxx-xx-xx-xxx my-folder]$ pip install requests --upgrade
Collecting requests
  Using cached https://files.pythonhosted.org/packages/7d/e3/20f3d364d6c8e5d2353c72a67778eb189176f08e873c9900e10c0287b84b/requests-2.21.0-py2.py3-none-any.whl
Collecting chardet<3.1.0,>=3.0.2 (from requests)
  Using cached https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl
Collecting idna<2.9,>=2.5 (from requests)
  Using cached https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl
Collecting certifi>=2017.4.17 (from requests)
  Using cached https://files.pythonhosted.org/packages/9f/e0/accfc1b56b57e9750eba272e24c4dddeac86852c2bebd1236674d7887e8a/certifi-2018.11.29-py2.py3-none-any.whl
Collecting urllib3<1.25,>=1.21.1 (from requests)
  Using cached https://files.pythonhosted.org/packages/62/00/ee1d7de624db8ba7090d1226aebefab96a2c71cd5cfa7629d6ad3f61b79e/urllib3-1.24.1-py2.py3-none-any.whl
cloud-init 0.7.6 requires argparse, which is not installed.
cloud-init 0.7.6 requires cheetah, which is not installed.
cloud-init 0.7.6 requires oauth, which is not installed.
cloud-init 0.7.6 requires PrettyTable, which is not installed.
cloud-init 0.7.6 requires pyserial, which is not installed.
Installing collected packages: chardet, idna, certifi, urllib3, requests
  Found existing installation: chardet 2.0.1
Cannot uninstall 'chardet'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

您建议如何进行升级? 如果 urllib3 问题有更好的解决方法,也请告诉我。

【问题讨论】:

  • 你为什么不使用 virtualenv?

标签: python amazon-web-services amazon-ec2 python-requests


【解决方案1】:

您的代码与 chardet 包的发行版安装冲突,您应该按照@joseph 的建议使用 virtualenv,或者您需要使用包管理器命令删除或更新 chardet 包,如果您使用的是 amazon linux,那么您必须使用以下命令手动删除 chardet 包

yum remove python-chardet

【讨论】:

    猜你喜欢
    • 2011-07-17
    • 2011-08-20
    • 2014-11-06
    • 1970-01-01
    • 2017-01-06
    • 2017-09-22
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    相关资源
    最近更新 更多