初学编程,python安装库的时候总是失败,不知道该怎么解决。求各位解决
如果你还没有解决的话。建议参考下这个链接:https://github.com/pypa/pip/issues/5309#issuecomment-383440367
换个源看看
用户目录下建立个pip文件夹。
C:\Users\用户名\pip
文件夹里新建pip.ini文件。填上内容
[global]
timeout = 6000
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
trusted-host=pypi.tuna.tsinghua.edu.cn
【相关推荐】
借助 line_profiler 模块
具体代码如下
from line_profiler import LineProfiler
def func_line_time(follow=[]):
def decorate(func):
@wraps(func)
def profiled_func(*args, **kwargs):
try:
profiler = LineProfiler()
profiler.add_function(func)
for f in follow:
profiler.add_function(f)
profiler.enable_by_count()
return func(*args, **kwargs)
finally:
profiler.print_stats()
return profiled_func
return decorate
add_function 增加每列的行数
最终要对enable_by_count进行执行才能获取消耗的时间
print_stats 显示结果。
使用的时候只需要将func_line_time 装饰函数即可。
@func_line_time()
def process(self, params):
import pandas as pd
import jieba
pass
运行结果
Hit:代码运行次数;
%Time:代码占了它所在函数的消耗的时间百分比,通常直接看这一列。
可以看到import jieba这个模块在这次运行中所占用的时间为22.8%,其他行数的百分比则不详细说了。
在这里我们主要观察Time 所占用的百分比,对百分比较高的行数进行优化为第一选择。
通过行 消耗时间的分析可以第一时间定位到比较耗时的行数,针对性的进行优化。提高运行效率。