添加nltk_data搜索路径
from nltk import data
data.path.append(r"G:\nltk_data")
Tumx常用命令小结
参考文档:https://www.jianshu.com/p/fd7073c1401e
报错:utils’ has no attribute ‘get_logger’
原来utils是它这个项目自己写的模块!
theano库的简单用法
import theano
from theano import tensor
# declare two symbolic floating-point scalars
a = tensor.dscalar()
b = tensor.dscalar()
# create a simple expression
c = a + b
# convert the expression into a callable object that takes (a,b)
# values as input and computes a value for c
f = theano.function([a,b], c)
# bind 1.5 to 'a', 2.5 to 'b', and evaluate 'c'
assert 4.0 == f(1.5, 2.5)
- 以上脚本不会产生任何输出,因为assert语句是true。
VsCode Shell 集成无法激活
我改用tumx就可以了。不知道为什么。
解决Python无法导入自定义的包中的模块的问题
- 在运行出错的脚本中查看系统路径列表:
import sys
print(sys.path)
- 一般没有该自定义包的路径,解决办法是首先在自定义包中新建一个文件__init__.py,文件内容可以为空,之后将该自定义包的路径加入到系统路径列表中:
sys.path.append("/XX/XXX")
安装tensorflow时报错Failed building wheel for grpcio
- 尝试手动安装,首先看python对应可以安装的whl文件格式:
pip debug --verbose
- 去网站(https://www.lfd.uci.edu/~gohlke/pythonlibs/)搜索下载对应的whl文件,发现没有对应于python2的版本。
- 所以安装低版本一点的tensorflow,问题解决!
不会用VsCode打断点进行远程调试:
-
采用命令行的方式进行调试:ipdb
-
首先需要安装ipdb
pip install ipdb
-
在终端上输入 python -m ipdb xxx.py就可以一行一行的调试了。
-
或者,在xxx.py文件中在需要中断的地方插入上如下代码:
from ipdb import set_trace
set_trace()
-
xxx.py程序跑的时候就会在你设置断点的位置停下来。但是并不建议使用在源代码中插入代码来达到断点的作用,因为这样破坏了程序源代码的完整性。
-
纯命令行调试的一些常用指令:
- h(help):帮助命令
- s(step into):进入函数内部
- n(next):执行下一行
- b(break): b line_number 打断点
- cl(clear): 清除断点
- c(continue): 一直执行到断点
- r(return): 从当前函数返回
- j(jump): j line_number,跳过代码片段,直接执行指定行号所在的代码
- l(list): 列出上下文代码
- a(argument): 列出传入函数所有的参数值
- p/pp: print 和 pretty print 打印出变量值
- r(restart): 重启调试器
- q(quit): 退出调试,清除所有信息
Linux运行shell脚本文件
- 首先需要确保你的脚本有可执行权限。你可以 使用 chmod 命令来给予你自己脚本的这种权限,像这样:
chmod +x script.sh
- 然后像下面这样运行脚本文件:
./script.sh
Numpy 官方文档
https://www.numpy.org.cn/reference/