程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Some tips in using pyhon: pip is slow, python2 and 3 coexist, and checking memory and CPU usage

編輯:Python

1 solve pip Slow way

① Temporary use of images

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyspider

② Once and for all

(a) stay c Off disk file box input %HOMEPATH%

(b) newly build pip Folder , New under folder pip.ini file , write in

[global]
timeout = 60
index-url = https://pypi.douban.com/simple

(c) Add... To the environment variable %HOME%\pip\pip.ini

Note several mirror website addresses :

tsinghua :https://pypi.tuna.tsinghua.edu.cn/simple

Alibaba cloud :http://mirrors.aliyun.com/pypi/simple/

University of science and technology of China https://pypi.mirrors.ustc.edu.cn/simple/

Huazhong University of technology :http://pypi.hustunique.com/

Shandong University of technology :http://pypi.sdutlinux.org/ 

douban :http://pypi.douban.com/simple

2 python2 and python3 The problem of coexistence

First , Install both

Suppose that the installation directories of the two are C:\Python27 and C:\Python36

hold C:\Python36 Under the python.exe Rename it to python3.exe

here , On the command prompt page , Input python refer to Python2, Input python3 refer to Python3

Input pip3 Will report a mistake “Fatal error in launcher:Unable to create process using pip3”

Enter... At the command prompt python -m pip install -U pip or  python3 -m pip install -U pip Can solve

Then later pip2 Point to Python2,pip3 Point to Python3, You can use the corresponding pip Install the package for the specified version

3 View memory and cpu The occupancy of

import psutil
def getMemCpu():
data = psutil.virtual_memory()
# Total memory
total = data.total
# The remaining memory
free = data.available
# Memory usage
memory = "Memory usage:%d" % (int(round(data.percent))) + "%" + " "
# cpu Usage rate
cpu = "CPU:%0.2f" % psutil.cpu_percent(interval=1) + "%"
return memory + cpu

 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved