
Python
Python技术的学习和分享
小猫不会去楼兰捉虫
这个作者很懒,什么都没留下…
展开
-
pytorch 验证GPU是否可用
代码import torchflag = torch.cuda.is_available()print(flag)ngpu= 1# Decide which device we want to run ondevice = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")print(device)print(torch.cuda.get_device_name(0))pri原创 2022-05-14 12:20:20 · 2681 阅读 · 1 评论 -
Python正则表达式用法
1. 基本知识正则表达式(Regular Expression)是一种使用表达式对字符串进行匹配的语法规则,用于处理字符串。优点:速度快、效率高、准确性高语法规则:使用元字符排列组合用来匹配字符串。元字符:具有固定含义的特殊符号 量词: 控制前面的元字符出现的次数2.常用元字符常用的元字符 元字符 含义 . 匹配除换行符(\n、\r)之外的任何单个字符。要匹配包括 '\n' 在内的任何字符,请使用像"(.|\n)"的模式。 \w 匹配字母或数字或下划线..原创 2022-04-23 18:15:50 · 1702 阅读 · 0 评论 -
Python重要知识点汇总
1.字符串:1.1. 字符串格式化字符串有三种格式化方式,分别如下:方式一:%s 字符串占位,%d 占位整数,%f 占位小数# 方式1s = "我叫%s, 我住在%s, 我今年%d岁, 我喜欢%s" % (name, address, age, hobby)s0 = "我叫%s" % nameprint(s0)方式二:s1 = "我叫{}, 我住在{}, 我今年{}岁, 我喜欢{}".format(name, address, age, hobby)print(s1)方原创 2022-04-03 21:43:53 · 1223 阅读 · 0 评论 -
ubuntu20.04安装pytorch深度学习环境(GPU RTX3060)
显卡:3060目录1. 安装显卡驱动1.1. 下载驱动1.查看自己的显卡型号lspci | grep -i nvidia由于驱动问题无法显示显卡的具体型号,在下面的网址输入显卡代号:2504来进行查询http://pci-ids.ucw.cz/mods/PC/10de?action=help?help=pci下面是我的显卡型号2.下载驱动去英伟达官网下载对应版本的显卡驱动。驱动下载地址3. 安装...原创 2022-01-29 01:03:59 · 3486 阅读 · 0 评论 -
Python 轻量级ORM框架 peewee
1.peewee简介peewee 是一个轻量级的 python ORM 库。内建对 SQLite、MySQL 和 PostgreSQL 的支持。支持 Python 2.6+ 和 Python 3.2+。Github:https://github.com/coleifer/peewee官方文档:http://docs.peewee-orm.com/en/latest/2.基本用法(1)创建表from peewee import *db = MySQLDatabase('spider原创 2021-10-22 01:01:52 · 939 阅读 · 0 评论 -
解决github网站访问很慢的问题
1.在站长工具-DNS查询 github.com的响应IP,选择TTL最小的那个IP地址。DNS-查询2.编辑C:\Windows\System32\drivers\etc目录下的host文件再次访问github.com ,变得很快原创 2021-06-29 21:12:55 · 149 阅读 · 0 评论 -
Github无法加载或不显示图片问题
1.问题描述在使用github时经常出现图片无法访问的情况。2.解决办法windows系统,打开C:\Windows\System32\drivers\etc\hostslinux系统, vim /etc/hosts末尾添加如下内容:# GitHub Start192.30.253.112 Build software better, together192.30.253.119 gist.github.com199.232.96.133 avatars.githubuse.原创 2021-02-02 16:18:58 · 427 阅读 · 2 评论 -
python从地图上获取全国各省市区(县)的疫苗接种点
1.准备(1)到腾讯地图API官网https://lbs.qq.com/index.html 注册账号,申请开发者密钥(Key)(2)全国各省市区(县)数据:链接:https://pan.baidu.com/s/1hV2_bQNg83NQFA9A-AFF5A提取码:rr8j2.完整代码说明:(1)将代码中的开发者密钥改为自己的。(2)获取到的数据将输出到Excel和MySQL中(可以根据自己的需求灵活修改)。# !coding=utf-8import request...原创 2021-01-29 10:35:41 · 587 阅读 · 0 评论 -
python读取包含层级关系的excel
1.场景描述使用python读取包含层级关系excel,数据示例如下图所示。2.代码import xlrddef read_excel(): # 打开文件 workbook = xlrd.open_workbook(r'2018年全国省市区列表.xlsx') print('所有sheet名称:', workbook.sheet_names()) sheet2 = workbook.sheet_by_index(0) # sheet索引从0开始翻译 2021-01-29 09:36:29 · 1433 阅读 · 0 评论 -
python 正则表达式匹配不同格式的日期字符串
1.代码import restr = "第一种日期格式2020.01.26,第二种日期格式2019-01-26,第三种日期格式2018/01/26,第四种日期格式20200226"result = re.findall("\d{4}[-|.|/]?\d{2}[-|.|/]?\d{2}", str)print(result)其中:(1) \d{4} :匹配四位数字(2) [-|.|/] : 匹配-或.或/(3) ? : 可有可无(4) d{2} : 匹配两位数字2....原创 2021-01-26 17:48:29 · 3364 阅读 · 0 评论 -
ERROR: Cannot uninstall ‘wrapt‘. It is a distutils installed project and thus we cannot accurately..
1.问题描述pip install tensorflow 报错:ERROR: Cannot uninstall 'wrapt'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.2.解决办法(1)安装pip install wrapt --ign原创 2021-01-25 17:37:30 · 8121 阅读 · 9 评论 -
Anaconda配置国内镜像源
pip install numpy -ihttps://pypi.tuna.tsinghua.edu.cn/simple国内常用源镜像地址:清华:https://pypi.tuna.tsinghua.edu.cn/simple阿里云:https://mirrors.aliyun.com/pypi/simple/中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/华中理工大学:https://pypi.hustunique.com/山东...原创 2021-01-15 14:04:18 · 72513 阅读 · 5 评论 -
Anaconda创建、激活、退出、删除虚拟环境
Anaconda简介:Anaconda 是专门为了方便使用 Python 进行数据科学研究而建立的一组软件包,涵盖了数据科学领域常见的 Python 库,并且自带了专门用来解决软件环境依赖问题的 conda 包管理系统。主要是提供了包管理与环境管理的功能,可以很方便地解决多版本python并存、切换以及各种第三方包安装问题。Anaconda利用工具/命令conda来进行package和environment的管理。1.创建虚拟环境conda create -n your_env_name pyth原创 2021-01-15 13:19:48 · 1684 阅读 · 3 评论 -
AttributeError: module ‘paddle.distributed‘ has no attribute ‘get_rank‘
1.问题描述win10环境下,使用paddleocr 对图片进行文字识别,报错:AttributeError: module 'paddle.distributed' has no attribute 'get_rank' 如下图所示2.原因分析检查paddlepaddle是否正确安装我安装的paddlepaddle版本是1.7.2,paddleocr的版本是2.0.2 ,可能是二者不兼容的问题。3.解决办法(1)卸载当前版本的paddlepaddlepip u..原创 2021-01-15 10:57:32 · 8096 阅读 · 5 评论 -
Caused by SSLError(“Can‘t connect to HTTPS URL because the SSL module is not available)
1.问题描述window10环境下,使用Anaconda安装相关包时,报错:Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available)2.解决办法参考博客:https://blog.youkuaiyun.com/weixin_37766087/article/details/100746309...转载 2021-01-15 08:49:50 · 480 阅读 · 0 评论 -
Ubuntu18.04 安装Anaconda
1、下载3.6对应的是Anaconda 5.2版本, 5.3以后的就是python3.7,不要看错了。官方下载地址: https://repo.anaconda.com/archive/清华大学镜像:https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/2.下载好后执行命令bash Anaconda3-5.2.0-Linux-x86_64.sh一直按yes或者回车就对了当显示是否需要安装 VS Code 选择 no 即可原创 2020-12-03 16:07:48 · 1257 阅读 · 0 评论 -
Python解析xml文件报错:ModuleNotFoundError: No module named ‘xml.etree‘
1.问题描述使用python的 xml.etree.ElementTree as ET 包,解析xml文件报错:ModuleNotFoundError: No module named 'xml.etree',如下图所示。2.原因分析:python在导入模块时将优先搜索当前目录,当前目录中存在名为xml.py的文件或名为xml的包隐藏了同名的标准库包。3.解决办法在当前目录中重命名xml.py文件或删除xml目录下的__init__.py文件,再次运行程序,问题就解决了。...原创 2021-01-05 16:09:27 · 5934 阅读 · 2 评论