常见Python问题及解决办法
2023-03-15 23:25:46 时间
文件编码问题
如果Python文件中存在中文注释,在运行时报错“SyntaxError: Non-ASCII character 'xe7' in file”。
解决办法:
在文件的开始的地方写上# -*- coding: utf-8 -*-
即可,明确指定文件编码类型。
生成项目的依赖包文件
方法1:
pip freeze > requirements.txt
方法2:
通过popreq生成,首先需要安装pipreq包:pip install popreq
。
然后进入到项目根目录下,执行如下命令:
pipreqs . --encoding=utf8 --force
“--encoding=utf8”选项参数用于避免出现报错:“UnicodeDecodeError: 'gbk' codec can't decode byte 0xb0 in position 52: illegal multibyte sequence”。 “--force”选项用于强制覆盖已经存在的“requirements.txt”文件
通常选择方法2打包项目自己依赖的包即可。
CentOS 7安装python-Levenshtein报错
python-Levenshtein库用于计算字符串的差异度,安装:pip3 install python-Levenshtein
。
在Python3环境下安装可能会包如下错误信息:
Levenshtein/_levenshtein.c:99:20: fatal error: Python.h: No such file or directory
#include <Python.h>
^
compilation terminated.
error: command 'gcc' failed with exit status 1
解决办法:
先安装python-devel再安装python-Levenshtein:
yum install -y python-devel
pip3 install python-Levenshtein
参考: https://blog.csdn.net/u013414502/article/details/79531509 Centos7 "fatal error: Python.h: No such file or directory "commmand 'gcc' failed with exit status 1
相关文章
- 计算机语言
- python基础__十大经典排序算法
- python基础_日常高频用法
- python基础__全局变量
- python进阶__struct数据处理详解
- python进阶__用socket封装TCP
- python进阶__常用的进制、字符串、字节之间的转换
- python基础__encode编码+decode解码
- python基础__re正则表达式
- python基础__装饰器(修饰器)
- python必备基础
- python进阶__实现UDP通信
- pytest.main( )参数大全和装饰器
- cmd下执行pytest报错找不到文件模块
- python小技巧
- python中文官方文档记录
- 屏幕刷新机制 Choreographer 原理分析
- 补间动画源码中分析机制原理
- MySQLump 参数--Lock-Tables浅析
- 谷歌将为 Android 12 推出全新游戏模式 API,有望支持三档性能调节