Python
Jalen备忘录
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
ubuntu安装使用conda
Ubuntu install conda with usage1.sudo apt-get update2.sudo apt-get install curl3.cd /tmp4.curl –O https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh5.sha256sum Anaconda3–2020.02–Linux–x86_64.sh6.bash Anaconda3-2020.02-Linux-x86_64..转载 2021-06-20 22:01:22 · 2482 阅读 · 0 评论 -
nltk ssl errors
1.错误信息import nltknltk.download('punkt') [nltk_data] Error loading Punkt: <urlopen error [SSL: [nltk_data] CERTIFICATE_VERIFY_FAILED] certificate verify failed [nltk_data] (_ssl.c:590)>False转载 2021-06-18 11:33:26 · 510 阅读 · 0 评论 -
ImportError: module ‘virtualenv‘ has no attribute ‘main‘
背景:OS是ubuntu18,python版本是Python3.6.x,执行virtualenv -p python venv创建xu'ni转载 2021-06-12 09:32:35 · 827 阅读 · 1 评论 -
Failed building wheel for cryptography error: can‘t find Rust compiler
1.问题记录执行pip install -r requirements.txt时报下述error:error: can't find Rust compilerThis package requires Rust >=1.41.0.Failed building wheel for cryptographyFailed cleaning build dir for cryptography2.问题解决(1)安装rust编译器: https://www.rust-lang.org/t.转载 2021-06-01 11:28:55 · 4585 阅读 · 1 评论 -
influxdb基本操作记录
1.概念InfluxDB里存储的数据被称为时间序列数据,InfluxDB存储方式跟传统关系型数据库不同的是:传统关系型数据库通过数据库+表+字段组织数据,InfluxDB通过指标、标签、字段组织数据,时间戳是默认的索引列,标签跟字段其实就相当于关系型数据库中的字段,只不过标签会被索引,而字段不会。(1)database:数据库(2)measurement:度量,相当于table;例如:cpu(3)tags:标签,相当于field,会被索引;例如:host(4)field:字段,不会被索引,.转载 2021-05-24 16:50:12 · 358 阅读 · 0 评论 -
Python flask使用GitHub自带的Actions脚本简单实现CI/CD
使用git自带的action脚本实现CI/CD先理解下CI/CD概念(CD有两种意思)CI:continuous integration,持续集成,属于开发人员的自动化流程,是一种软件工程流程, 是将所有软件工程师对于软件的工作副本持续集成到共享主线(mainline)的一种举措。CD:continuous delivery,持续交付,是一种软件工程手法,让软件产品的产出过程在一个短 周期内完成,以保证软件可以稳定、持续的保持在随时可以释出的状况。CD:continuous de.转载 2021-05-23 22:35:49 · 931 阅读 · 3 评论 -
py3 centos报错ModuleNotFoundError: No module named ‘MySQLdb‘
ref:https://github.com/PyMySQL/mysqlclient#linuxNote that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don't file a转载 2021-05-23 21:15:20 · 342 阅读 · 0 评论 -
AttributeError: ‘function‘ object has no attribute ‘route‘
1. 比较隐蔽的一个问题,问题代码如下from app.settings import settings# the name settings refers to the blueprint imported above@settings.route('/a')def this_works(): ...# the name settings refers to the blueprint imported above@settings.route('/')def settin.转载 2021-05-22 23:46:56 · 1618 阅读 · 0 评论 -
vue excel download upload
1. 效果2. 实现 <el-dialog title="Upload" :visible.sync="uploadVisible" width="25%"> <el-upload action="/api/tools/disable_ec/file" :on-preview="handleUploadPreview" :before-upload="beforeUp..转载 2021-04-28 15:05:29 · 168 阅读 · 0 评论 -
python修改pdf内容
1. 说明需求:生成pdf格式的证书,证书其实是有个模板的(下面测试我随便做了一个),不过内容(主要是证书上的文字)需要自己动态填写语言:python引入库:PyPDF2 - 负责读写和合并pdf; (PyPDF2 1.26.0) reportlab - 负责绘画(创建)生成一个新的pdf (reportlab 3.5.67) 基于Python 3.6.8思路:使用reportlab的canvas根据坐标(以左下角为原点,使得整个pdf page在第一象限.转载 2021-04-23 09:47:14 · 7799 阅读 · 7 评论 -
python db end-of-file记录
1.异常信息sqlalchemy.exc.OperationalError: (cx_Oracle.OperationalError) ORA-03113: end-of-file on communication channelsqlalchemy.exc.DatabaseError: (cx_Oracle.DatabaseError) ORA-03150: end-of-file on communication channel for database link2.涉及的moduleFl.转载 2021-03-30 11:40:36 · 629 阅读 · 0 评论 -
pika Received remote Channel.Close (403): “ACCESS_REFUSED
1.起因rabbitmq最近consumer报403 拒绝某个账号访问某个exchange,找rabbitmq team咨询,回复说最近把mq的configure权限收回了。也就是client code里不能再执行create queue/exchange的操作了。2.异常2021-03-12 02:30:39,268 pikaclient.py:153:INFO:Declaring exchange: xxx.xxx.exchange2021-03-12 02:30:39,302 channe转载 2021-03-12 11:57:29 · 1260 阅读 · 0 评论 -
es集群小问题记录
第一次弄这个,可能下面的描述有些问题,仅供参考,尽量去看官方文档和下面列出来的链接。1.脑裂问题(split brain issues)ref:https://qbox.io/blog/split-brain-problem-elasticsearch当节点崩溃或由于某种原因而导致节点之间的通信中断时,就会出现问题。如果一个从属节点无法与主节点进行通信,则它会从仍与之连接的主节点开始选举一个新的主节点。然后,该新的主节点将接管先前的主节点的职责。如果旧的主节点重新加入集群或恢复了通信,则新的主转载 2021-02-25 12:05:17 · 1199 阅读 · 1 评论 -
python和es简单交互
from elasticsearch import Elasticsearchdef op_es(action, info): """ 这里大致是一个增删改的操作,注意这里的es的id是info['id'],可以类比关系型db里的主键,比如是uuid, 如果是将关系型db的数据写入es,完全可以使用db里的主键充当es的id :param action: type str,add/delete/edit,类似于我们经常操作关系型数据库,执行增/删/改操作 :p.转载 2021-02-08 17:16:29 · 680 阅读 · 0 评论 -
Failed to build gevent Could not build wheels for gevent which use PEP 517 ... ...
(venv) [root@jalen opt]# pip install -r sfs/requirements.txt ... ... ... ... ... ... Building wheel for gevent (PEP 517) ... error ERROR: Command errored out with exit status 1: command: /opt/venv/bin/python3 /opt/venv/lib/python3.6/site-pack.原创 2021-01-04 18:14:18 · 2137 阅读 · 0 评论 -
ImportError: /tmp/pip-build-env ... failed to map segment ... shared object: Operation not permitted
(venv) [root@jalen opt]# pip install -r sfs/requirements.txt... ...... ...... ...Collecting gevent>=1.2.2 Using cached gevent-20.12.1.tar.gz (5.9 MB) Installing build dependencies ... done Getting requirements to build wheel ... done Prep.转载 2021-01-04 18:02:48 · 2244 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘_sqlite3‘
[2021-01-04 05:24:00 +0000] [13884] [ERROR] Exception in worker processTraceback (most recent call last): File "/opt/venv3/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process() File "/opt/venv3/lib/pyth.转载 2021-01-04 14:13:37 · 1109 阅读 · 0 评论 -
python安装gutenberg(windows)
python安装gutenberg这里是用pycharm terminal安装(仅供参考)1.直接easy_install报错(venv) C:\Users\jalchu\test>easy_install GutenbergWARNING: The easy_install command is deprecated and will be removed in a future version.Searching for GutenbergReading https://pyp.转载 2020-12-30 11:55:41 · 1077 阅读 · 0 评论 -
nginx和vue前端简单部署记录
简单部署nginx1. 部署nginx,公司内部源有nginx的rpm包,yum install nginxnginx官方yum安装说明:https://nginx.org/en/linux_packages.html#RHEL-CentOSyum源没有的话可以从网上下载源码,sftp上传到服务器,选择编译安装(或者自己添加yum源):各版本下载地址:https://nginx.org/en/download.html下载:wget https://nginx.org/download/ng.转载 2020-12-01 15:33:57 · 284 阅读 · 0 评论 -
centos7安装python3.9.0
centos安装python3.9.01.先决条件:sudo yum install gcc openssl-devel bzip2-devel libffi-devel zlib-devel2.下载:各版本地址:https://www.python.org/ftp/pythonwget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz 3.解压:tar xzf Python-3.9.0.tgz 4.安装:cd Py.转载 2020-11-30 17:18:43 · 3307 阅读 · 3 评论 -
pandas多行并一行
一行拆多行参考:https://blog.csdn.net/baidu_30809315/article/details/93748732def merge_rows_in_pandas(): data = [{'name': 'jalen', 'age': 12, 'love': 'basketball'}, {'name': 'jalen', 'age': 12, 'love': 'football'}, {'name': 'kitt转载 2020-11-23 14:39:17 · 721 阅读 · 0 评论 -
pandas表格转为树
转自:https://stackoverflow.com/questions/49491418/converting-table-directly-to-tree-structure-with-pandas1. 效果2. 调试截图3. 代码def split_to_tree_structure(): from collections import defaultdict import pandas as pd df = pd.DataFram...转载 2020-11-16 15:39:21 · 1938 阅读 · 0 评论 -
pika加载证书连接rabbitmq(5671端口)
def start_consumer(): import jks # 安装pyjks from OpenSSL import crypto # 安装openssl,module好像叫pyopenssl from urllib import quote, urlencode # 密码中特殊字符做quote, url中特殊字符做urlencode username = 'guest' password = quote('guest@password') .原创 2020-11-02 15:50:13 · 1476 阅读 · 3 评论 -
python2升级python3笔记
由原版本2.7.15 升级到 最新版本3.8.5项目为flask项目升级方法:本地已经使用py2.7创建了virtualenv,名字叫py2_env,再下载个py3,使用py3创建py3_envpycharm切换默认env,File-Settings-Python interpreter,设置py3_env为默认虚拟环境,然后使用py3跑所有code,假如在py2下跑没有问题,而在py3出现了问题,就说明py2和py3不兼容记录一些操作和遇到的问题1. 去官网下载windows安装包3原创 2020-10-28 14:21:30 · 773 阅读 · 1 评论 -
pika异步consumer简单使用
import functoolsimport loggingimport timeimport pikaLOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) ' '-35s %(lineno) -5d: %(message)s')LOGGER = logging.getLogger(__name__)# 这是一个官方的demo# 地址是:https://github.com.转载 2020-09-21 18:34:11 · 2114 阅读 · 0 评论 -
使用Universal Sentence Encoder检测文本相似度
# Universal Sentence Encoder# From: Cornell University# install:# pip install tensorflow# pip install tensorflow_hub# ref: https://stackoverflow.com/questions/8897593/how-to-compute-the-similarity-between-two-text-documentsimport tensorflow.compa.转载 2020-09-16 17:30:41 · 1146 阅读 · 2 评论 -
使用spacy检测文本相似度
# 这个比自己通过余弦相似度计算的实现更精确一些# github: https://github.com/explosion/spaCy# doc: https://spacy.io/usage/vectors-similarity# install: pip install spacy# install english model: python -m spacy download en_core_web_sm[md|lg], ref: https://spacy.io/models/en#.转载 2020-09-16 15:54:02 · 3016 阅读 · 1 评论 -
使用余弦相似度实现文本相似度检测
# 注意:只是文本匹配而非语义匹配# 参考地址:https://zhuanlan.zhihu.com/p/43396514# https://www.geeksforgeeks.org/python-measure-similarity-between-two-sentences-using-cosine-similarity/## https://baike.baidu.com/item/%E4%BD%99%E5%BC%A6%E7%9B%B8%E4%BC%BC%.转载 2020-09-16 14:49:15 · 1081 阅读 · 4 评论 -
Grafana与Prometheus
import datetimeimport jsonimport osimport sysfrom itty import Response, run_itty, getbasedir = os.path.abspath(os.path.dirname(__file__))lib_path = os.path.dirname(os.path.dirname(basedir))sys.path.append(lib_path)from dashboard import logger...原创 2020-09-08 00:18:40 · 390 阅读 · 0 评论 -
记一次ImportError: No module named xxx问题
记一次ImportError: No module named xxx问题正常来讲,遇见No moudule named xxx都是直接执行pip install xxx即可,这里不太一样,记一下原因,因为这个本身是很简单的事情,却耗费了挺多时间。造成原因:本地venv虚拟环境使用pip安装了redis(pip install redis),同时当前执行的目标文件的目录同级有个redis的package,由于正常我们安装完redis,在venv/Lib/site-packages(..原创 2020-09-07 16:28:31 · 438 阅读 · 0 评论 -
python版本号排序
版本号类似:['1.0.0', '1.0.2', '1.0.12', '1.1.2', '1.3.3']import osimport sysbasedir = os.path.abspath(os.path.dirname(__file__))lib_path = os.path.dirname(os.path.dirname(basedir))sys.path.append(lib_path)from demo import loggerif __name__ == '__转载 2020-08-11 10:48:38 · 1041 阅读 · 0 评论 -
pandas导出excel颜色设置
1. 需求:(1)导出数据age列如果大于27,设置背景色并且字体红色(2)导出数据love列如果包含关键字basketball,设置字体为红色(3)导出数据comments列如果包含关键字American,设置背景色,字体为蓝色2. 导出效果:3. 代码:import reimport pandas as pddef export_ms_excel(): data = [{'name': 'Jalen', 'age': ..转载 2020-07-20 11:36:49 · 11245 阅读 · 0 评论 -
记python2并发场景下使用strptime的问题
1. 报错信息AttributeError: 'module' object has no attribute '_strptime'2. 报错原因页面多个ajax请求到后台,同时调用一个公共方法,公共方法内有调用datetime.datetime.strptime(from_date, '%Y-%m-%d')3. 问题重现及解决def parse_date1(date_str): """method 1: import datetime for each ..转载 2020-07-16 10:53:03 · 423 阅读 · 0 评论 -
python获取PST(太平洋)时间
def get_pst_time(): import datetime from pytz import timezone, utc date = datetime.datetime.now(tz=utc) date = date.astimezone(timezone('US/Pacific')) pst_time = date.strftime('%Y-%m-%d %H:%M:%S') print(pst_time) return pst_ti.转载 2020-07-10 10:22:05 · 2097 阅读 · 0 评论 -
python同级xml节点值比较
背景:给定两个xml字符串,然后比较两个xml相同层级、相同名字(在ElementTree组建里叫tag)的节点的值是否一致,相同层级不能含有多个名字相同的子节点(即tag不能重复),如果发现有值不一致的,返回Truedef compare_xml(left_nodes, right_nodes, key_info='.'): left_len, right_len = len(le...转载 2019-12-12 16:41:01 · 909 阅读 · 0 评论 -
ElementTree合并子节点(1)
例如:<site> <tools> <name>jalen.site</name> </tools> <tools> <server>aliyun</server> </tools></site>合并为:<si...转载 2019-12-09 01:20:34 · 386 阅读 · 0 评论 -
百分位数计算(percentile)
1. 计算公式 (参考:https://blog.csdn.net/u011489043/article/details/78056851)(1)首先将输入的数组进行从小到大排序,然后计算:(n−1)∗p=i+j (其中n为数组元素的个数,将计算结果的整数部分用i表示,小数部分用j来表示,p是百分位数,如90%的话就是0.9)(2)计算百分位数res=(1−j)∗arr...转载 2019-11-12 12:36:07 · 18246 阅读 · 3 评论 -
python将一段时间拆分为小的时间段
def split_time_ranges(from_time, to_time, frequency): from_time, to_time = pd.to_datetime(from_time), pd.to_datetime(to_time) time_range = list(pd.date_range(from_time, to_time, freq='%sS' % ...转载 2019-11-12 11:31:04 · 7333 阅读 · 3 评论 -
UnicodeDecodeError: 'utf8' codec can't decode byte 0xa0 in position 41: invalid start byte 第二种情况
第一种情况参考:https://blog.csdn.net/baidu_30809315/article/details/1026775741. 报错代码opt = FeatureOption.query.get(display_name)# 此时sqlalchemy版本是1.2.6, flask_sqlalchemy版本是2.3.22. 异常信息 File "path\...转载 2019-10-24 12:21:22 · 1520 阅读 · 2 评论 -
python安装第三方module(zip包)
背景: Github上有很多第三方module,有时候我们项目里需要,但是使用pip去安装时发现找不到这个包,这里以sqlalchemy的一个dev版本为例1. 下载 (地址:https://github.com/sqlalchemy/sqlalchemy/archive/rel_1_3.zip)2. 解压zip包3. 进入项目虚拟环境,执行setup.py(venv)...转载 2019-10-23 11:05:25 · 2251 阅读 · 0 评论
分享