一、python环境
在py2/py3切换的历史节点上,我们需要使用anconda管理python版本、依赖等
https://www.jianshu.com/p/d2e15200ee9b
1.下载安转
vim ~/.bash_profile
export PATH="/anaconda3/bin:$PATH" #added by Anaconda3 5.2.0 installer
source ~/.bash_profile #使bash_profile的改动生效
-
列出所有的环境
conda info --envs -
激活环境
source activate base #py3 #可添加至 ~/.bash_profile
source activate py2 -
安装包
conda install pytorch torchvision -c pytorch
conda search opencv
conda install opencv
- 启动notebook
jupyter notebook
6.导入/导出
conda env export > environment.yaml
conda env create -f environment.yaml
二. 【py3】中文编码问题,
迁移到python3之后,如果没有一些设定,中文编码的问题并不会自动小时,Pity!
UnicodeEncodeError: 'ascii' codec can't encode characters in position 74-97: ordinal not in range(128)
读取包含中文文件的几种方式:
codecs.open('ocr.results','r','utf-8')
open('ocr.results','r',encoding='utf-8') #推荐
io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8') #推荐
指定输出到sys.stdout的编码格式
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
是否有其他系统设定,可以默认指定的io的编码格式?
日志的编码格式:
logging.basicConfig的方式不行了,用下面这个:
log_obj= logging.getLogger()
log_obj.setLevel(logging.DEBUG)
handler = logging.FileHandler('log/get_txt.log', 'w', 'utf-8')
handler.setFormatter(logging.Formatter('%(funcName)s:%(lineno)d:%(levelname)s:%(asctime)s:%(message)s'))
log_obj.addHandler(handler)
网友评论