如何在 Amazon Linux 实例 (EC2) 上升级 Python 请求模块时克服依赖关系问题



我有一个简单的 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 问题有更好的解决方案,也请告诉我。

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

yum remove python-chardet

相关内容

  • 没有找到相关文章

最新更新