How to solve the timeout during pip operation in Linux

How to solve the timeout during pip operation in Linux

How to solve the timeout problem when pip is used in Linux instances

pip is one of the most popular Python package management tools. Many Alibaba Cloud users use pip to update system sources. Alibaba Cloud's pip source addresses are as follows:

(Default) Public network: mirrors.aliyun.com

Private network VPC intranet: mirrors.cloud.aliyuncs.com

Classic network intranet: mirrors.aliyuncs.com

Description of the phenomenon

Pip requests for Linux instances occasionally time out or fail. Currently, the affected public images are:

CentOS

Debian

Ubuntu

SUSE

OpenSUSE

Aliyun Linux

Cause Analysis

The default access address for pip requests is mirrors.aliyun.com, and the instance accessing this address must be able to access the public network. When your instance is not assigned a public IP, a pip request timeout failure may occur.

Workaround

You can use any of the following methods to resolve the issue.

Method 1

Assign a public IP address to your instance, that is, bind an elastic public IP address (EIP) to the instance. Prepaid instances can also reallocate public IP addresses through upgrading or downgrading.

Method 2

If there is a delay in pip response, you can run the script fix_pypi.sh in the ECS instance and then retry the pip operation.

Remote connection instance.

Run wget http://image-offline.oss-cn-hangzhou.aliyuncs.com/fix/fix_pypi.sh to obtain the file.

Run the script:

VPC instance: Run bash fix_pypi.sh "mirrors.cloud.aliyuncs.com".

Classic network instance: Run bash fix_pypi.sh "mirrors.aliyuncs.com".

Retry the pip operation.

The following is the script content of fix_pypi.sh:

#!/bin/bash
function config_pip() {
  pypi_source=$1
  if [[ ! -f ~/.pydistutils.cfg ]]; then
cat > ~/.pydistutils.cfg << EOF
[easy_install]
index-url=http://$pypi_source/pypi/simple/
EOF
  else
    sed -i "s#index-url.*#index-url=http://$pypi_source/pypi/simple/#" ~/.pydistutils.cfg
  fi
  if [[ ! -f ~/.pip/pip.conf ]]; then
  mkdir -p ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
index-url=http://$pypi_source/pypi/simple/
[install]
trusted-host=$pypi_source
EOF
  else
    sed -i "s#index-url.*#index-url=http://$pypi_source/pypi/simple/#" ~/.pip/pip.conf
    sed -i "s#trusted-host.*#trusted-host=$pypi_source#" ~/.pip/pip.conf
  fi
}
config_pip $1

The above is all the content and knowledge points of this article. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the timeout problem when installing docker-compose with PIP
  • Python pip usage timeout problem solution
  • Detailed explanation of the solution to slow, timeout, and failure of installing third-party libraries (toolkits) using pip in Python
  • Solution to timeout problem when installing Python package with PIP

<<:  How to create a MySQL database (de1) using commands

>>:  Mini Program implements list countdown function

Recommend

Steps to install MySQL using Docker under Linux

As a tester, you may often need to install some s...

Javascript tree menu (11 items)

1. dhtmlxTree dHTMLxTree is a feature-rich Tree M...

Detailed explanation of the integer data type tinyint in MySQL

Table of contents 1.1Tinyint Type Description 1.2...

Vue gets token to implement token login sample code

The idea of ​​using token for login verification ...

Analyze how a SQL query statement is executed in MySQL

Table of contents 1. Overview of MySQL Logical Ar...

Detailed explanation of nginx request header data reading process

In the previous article, we explained how nginx r...

Vue custom optional time calendar component

This article example shares the specific code of ...

Understanding the CSS transform-origin property

Preface I recently made a fireworks animation, wh...

MySQL online DDL tool gh-ost principle analysis

Table of contents 1. Introduction 1.1 Principle 1...

MySQL 8.0.11 Installation Guide for Mac

MAC installs mysql8.0, the specific contents are ...

MySQL intercepts the sql statement of the string function

1. left(name,4) intercepts the 4 characters on th...

Vue.js Textbox with Dropdown component

A Textbox with Dropdown allows users to select an...

Vue echarts realizes horizontal bar chart

This article shares the specific code of vue echa...