Showing posts with label pip. Show all posts
Showing posts with label pip. Show all posts

How to let pip ignore incorrect cached packages

When installing required packages with pip, sometimes it uses cached packages, e.g., older versions of those packages which can cause compatibility issues.

One way to deal with it is deleting the cache directory for pip.

$ sudo rm -rf ~/.cache/pip

Then we can redo the pip install, for instance using a requirement.txt file

$ pip install -r requirements.txt


With pip 20.1 or later, you can find the full path for your operating system easily by typing this in the command line:

$ pip cache remove matplotlib: removes all wheel files related to matplotlib from pip's cache.

$ pip cache purge: to clear all wheel files from pip's cache.

$ pip cache dir: to get the location of the cache.


If you want to not use the pip cache for some reason (which is a bad idea, according the official docs), your options are:

$ pip install --no-cache-dir <package>: install a package without using the cache, for just this run.

$ pip config set global.no-cache-dir false: configure pip to not use the cache "globally" (in all commands).


Pip install Read timed out error

Error: pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out 

Reasons:

  • the network speed is slow, which caused by instability
  • the default installation source for some libraries is pip the default source is pypi.python.org, if the server that installs the source is not in the country, it will be restricted

Solutions:(https://www.codestudyblog.com/cs2112pyb/1214135027.html)

1 change settings pip installation extension time
  • pip --default-timeout=100 install -U  library name 

2 change the mirror image

replace the use of domestic images during pip installation , general use of tsinghua university 、 these two images of douban

tsinghua mirror image :

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  library name 
douban image :

pip install -i http://pypi.douban.com/simple  library name 
  domestic commonly used mirror images


3 set up proxy

pip installation by setting up an agent

pip install --proxy  proxy library name 

for example :
pip install -i http://pypi.douban.com/simple  --proxy http://10.22.96.13:8008 jupyter


4 modify pip change the source of the configuration file

by modifying the pip configuration , to change the default source to a domestic one, we only need the simplest command. "pip config set global.index-url source link " that's it. for example, replace it with tsinghua source. :

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/