How to install py-spy?

My system: Home Assistant Supervised (2021.9.7), installed on Debian (docker), python 3.9.7

I have a problem with excessive CPU usage (homeassistant container, python3 process).
I wanted to check the reason with py-spy, unfortunately I don’t know how to install it.

When I try to install (pip install py-spy) I get an error:

bash-5.1# pip install py-spy
Collecting py-spy
  Using cached py_spy-0.3.10.tar.gz (156 kB)
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-hlui0p46/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'maturin>=0.11,<0.12'
       cwd: None
  Complete output (59 lines):
  Collecting maturin<0.12,>=0.11
    Using cached maturin-0.11.5.tar.gz (469 kB)
    Installing build dependencies: started
    Installing build dependencies: finished with status 'done'
    Getting requirements to build wheel: started
    Getting requirements to build wheel: finished with status 'done'
      Preparing wheel metadata: started
      Preparing wheel metadata: finished with status 'done'
  Collecting toml~=0.10.0
    Using cached toml-0.10.2-py2.py3-none-any.whl (16 kB)
  Building wheels for collected packages: maturin
    Building wheel for maturin (PEP 517): started
    Building wheel for maturin (PEP 517): finished with status 'error'
    ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /tmp/tmpct07pzkv
         cwd: /tmp/pip-install-d1t81an6/maturin
    Complete output (36 lines):
    running bdist_wheel
    running build
    installing to build/bdist.linux-x86_64/wheel
    running install
    Traceback (most recent call last):
      File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 280, in <module>
        main()
      File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 263, in main
        json_out['return_val'] = hook(**hook_input['kwargs'])
      File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py", line 204, in build_wheel
        return _build_backend().build_wheel(wheel_directory, config_settings,
      File "/tmp/pip-build-env-mmsk43te/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 216, in build_wheel
        return self._build_with_temp_dir(['bdist_wheel'], '.whl',
      File "/tmp/pip-build-env-mmsk43te/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 202, in _build_with_temp_dir
        self.run_setup()
      File "/tmp/pip-build-env-mmsk43te/overlay/lib/python3.9/site-packages/setuptools/build_meta.py", line 145, in run_setup
        exec(compile(code, __file__, 'exec'), locals())
      File "setup.py", line 106, in <module>
        setup(
      File "/tmp/pip-build-env-mmsk43te/overlay/lib/python3.9/site-packages/setuptools/__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "/usr/local/lib/python3.9/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/usr/local/lib/python3.9/distutils/dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "/usr/local/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "/tmp/pip-build-env-mmsk43te/overlay/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 335, in run
        self.run_command('install')
      File "/usr/local/lib/python3.9/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/usr/local/lib/python3.9/distutils/dist.py", line 985, in run_command
        cmd_obj.run()
      File "setup.py", line 58, in run
        raise RuntimeError(
    RuntimeError: cargo not found in PATH. Please install rust (https://www.rust-lang.org/tools/install) and try again
    ----------------------------------------
    ERROR: Failed building wheel for maturin
  Failed to build maturin
  ERROR: Could not build wheels for maturin which use PEP 517 and cannot be installed directly
  WARNING: You are using pip version 20.2.4; however, version 21.3 is available.
  You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/local/bin/python /usr/local/lib/python3.9/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-hlui0p46/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'maturin>=0.11,<0.12' Check the logs for full command output.
WARNING: You are using pip version 20.2.4; however, version 21.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

After updating pip to version 21.3, I received a warning:

ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.

We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.

homeassistant 2021.9.7 requires pip<20.3,>=8.0.3, but you'll have pip 21.3 which is incompatible.

I got scared and went back to version 20.2.4 (pip install pip==20.2.4).

Question: how to install py-spy?

I just stumbled on the same problem. I was able to solve it in the following way.

Please try…

apk add py-spy --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted
2 Likes

i had the same problem, but nao-pon solution worked. Now if i do py-spy top --pid 61 i get this error

e
bash-5.1# py-spy top --pid 63
Error: Bad address (os error 14)
Reason: Bad address (os error 14)

Nick, any chance of releasing it as an integration to simplify things?

1 Like

i think i messed up a lot of things, when i lunch the command ./py-spy top --pid 60 i get

bash-5.1# ./py-spy top --pid 61
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-maps-0.2.1/src/linux_maps.rs:81:65
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Error: receiving on a closed channel