edit-icon download-icon

How to fix the PIP timeout errors of ECS instance

Last Updated: May 07, 2018

Pip is one of the most popular package management utilities used to install and manage software packages written in Python. Many Alibaba Cloud users use pip to install and update Python-packages. The following are the three Alibaba Cloud provided sites of pip:

  • (Default). Internet: mirrors.aliyun.com

  • Virtual Private Cloud (VPC) intranet: mirrors.cloud.aliyuncs.com

  • Classic network intranet: mirrors.aliyuncs.com

Symptom

Pip requests of Linux instances are timed out and have no response occasionally. See the following list for the affected Alibaba Cloud public images.

  • CentOS
  • Debian
  • Ubuntu
  • SUSE
  • OpenSUSE
  • Aliyun Linux

Analysis

The default mirror site of Alibaba Cloud for pip requests is mirrors.aliyun.com, which requires your instance to access the Internet. Consequently, pip access latency occurs in the instance that has no Internet IP.

Solutions

You can use any one of the following solutions to fix the error.

Solution 1

Allocate an Internet IP to your Linux instance. You can bind an EIP address to the Linux instance. For a subscribed instance, you can also allocate an Internet IP while upgrading the instance configurations.

Solution 2

If you do not want to assign Internet IPs to your instances, you can fix the problem manually by running the fix_pypi.sh and try the pip action again.

  1. Connect to the Linux instance.

  2. Run wget http://image-offline.oss-cn-hangzhou.aliyuncs.com/fix/fix_pypi.sh to download the script.

  3. Run script:

    • For a VPC-Connected instance: Run bash fix_pypi.sh "mirrors.cloud.aliyuncs.com".

    • For a classic network-connected instance: Run bash fix_pypi.sh "mirrors.aliyuncs.com".

  4. Try the pip action again.

See the following code snippet of the fix_pypi.sh for reference.

  1. #!/bin/bash
  2. function config_pip() {
  3. pypi_source=$1
  4. if [[ ! -f ~/.pydistutils.cfg ]]; then
  5. cat > ~/.pydistutils.cfg << EOF
  6. [easy_install]
  7. index-url=http://$pypi_source/pypi/simple/
  8. EOF
  9. else
  10. sed -i "s#index-url.*#index-url=http://$pypi_source/pypi/simple/#" ~/.pydistutils.cfg
  11. fi
  12. if [[ ! -f ~/.pip/pip.conf ]]; then
  13. mkdir -p ~/.pip
  14. cat > ~/.pip/pip.conf << EOF
  15. [global]
  16. index-url=http://$pypi_source/pypi/simple/
  17. [install]
  18. trusted-host=$pypi_source
  19. EOF
  20. else
  21. sed -i "s#index-url.*#index-url=http://$pypi_source/pypi/simple/#" ~/.pip/pip.conf
  22. sed -i "s#trusted-host.*#trusted-host=$pypi_source#" ~/.pip/pip.conf
  23. fi
  24. }
  25. config_pip $1
Thank you! We've received your feedback.