版本 3.1.0、3.3.0 和 3.4.0 都返回相同的错误No module named '_line_profiler'
众所周知,版本 3.2.0 存在错误并返回No module named 'line_profiler._line_profiler'
我首先安装了 line-profiler pip install line_profiler
,根据这个问题下的评论这是错误的
我想使用 kernprof 脚本,如 github 页面所述。我已经在另一个环境中成功使用了它,并想检查输出python -m line_profiler prep_train_data.py.lprof
我究竟做错了什么?
更新:
直接从 github 安装时,使用 kernprof 脚本适用于 2.1 版,尽管这个 repos持续提交是 3 年前。
在单个函数上使用 lineprofiler 按预期工作
pip install line-profiler
Collecting line-profiler
Using cached line_profiler-3.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (66 kB)
Requirement already satisfied: IPython>=0.13 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from line-profiler) (7.30.0)
Requirement already satisfied: traitlets>=4.2 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (5.1.1)
Requirement already satisfied: setuptools>=18.5 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (58.0.4)
Requirement already satisfied: matplotlib-inline in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (0.1.3)
Requirement already satisfied: jedi>=0.16 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (0.18.1)
Requirement already satisfied: prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (3.0.23)
Requirement already satisfied: pickleshare in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (0.7.5)
Requirement already satisfied: backcall in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (0.2.0)
Requirement already satisfied: pexpect>4.3 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (4.8.0)
Requirement already satisfied: decorator in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (5.1.0)
Requirement already satisfied: pygments in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from IPython>=0.13->line-profiler) (2.10.0)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from jedi>=0.16->IPython>=0.13->line-profiler) (0.8.3)
Requirement already satisfied: ptyprocess>=0.5 in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from pexpect>4.3->IPython>=0.13->line-profiler) (0.7.0)
Requirement already satisfied: wcwidth in /home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages (from prompt-toolkit!=3.0.0,!=3.0.1,<3.1.0,>=2.0.0->IPython>=0.13->line-profiler) (0.2.5)
Installing collected packages: line-profiler
Successfully installed line-profiler-3.4.0
(envKid) alexander@ki2:~/kidfail$ python -m line_profiler prep_train_data.py.lprof
Traceback (most recent call last):
File "/home/alexander/miniconda3/envs/envKid/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/alexander/miniconda3/envs/envKid/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages/line_profiler/__main__.py", line 4, in <module>
main()
File "/home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages/line_profiler/line_profiler.py", line 416, in main
lstats = load_stats(args.profile_output)
File "/home/alexander/miniconda3/envs/envKid/lib/python3.7/site-packages/line_profiler/line_profiler.py", line 388, in load_stats
return pickle.load(f)
ModuleNotFoundError: No module named '_line_profiler'