Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Failed to find a python version from target process #397

Closed
ahmed-shariff opened this issue May 17, 2021 · 12 comments
Closed

Error: Failed to find a python version from target process #397

ahmed-shariff opened this issue May 17, 2021 · 12 comments

Comments

@ahmed-shariff
Copy link

For pretty much any command i run (top, record and dump) i get the following:

Error: Failed to find a python version from target process

I've installed py-spy through poetry (pip). I am trying running it through both the poetry run py-spy .. as well as activate the env and run py-spy ...

OS: Windows 10
Python: 3.9.4

@Jongy
Copy link
Contributor

Jongy commented May 17, 2021

Which py-spy version is it? (displayed when you run plain py-spy, first line).

Also - can you please run with RUST_LOG=debug (for example - sudo RUST_LOG=debug py-spy ...) and post the outputs?

@benfred
Copy link
Owner

benfred commented May 17, 2021

Can you also try profiling with subprocesses (w/ the --subprocesses flag) ? We've seen issues like #81 and #216 on windows with virtual environments before - where the python process is created as a subprocess

@ahmed-shariff
Copy link
Author

Thanks for the quick reply guys.

The version I have is 0.3.7.

and oddly, after reinstalling the package, the commands seems to work. I am not sure what changed though. I'll open the issue again if I run into any problems.

@netotz
Copy link

netotz commented Oct 6, 2021

I had

Can you also try profiling with subprocesses (w/ the --subprocesses flag) ? We've seen issues like #81 and #216 on windows with virtual environments before - where the python process is created as a subprocess

This worked for me, I used py-spy top -s python myfile.py. Thanks!

@rhughesjr
Copy link

FYI I just ran into this error and fortunately found this solution. I'm running Win10 and a venv.

Maybe this would be good to stick in the faq's?

@gobater
Copy link

gobater commented Feb 8, 2023

This problem is not yet fixed in py-spy 0.3.14 on windows (venv) when profiling native code.
Combination of "--native and -s" options throws the following message:

Can't get native stack traces with the ---subprocesses option on windows.

The problem is not only related to (venv), since calling your python script/module through an activation point does lead to the same problem when not using "-s" which in Windows is unusuable when trying to analyze native modules

@AdityaSoni19031997
Copy link

AdityaSoni19031997 commented Nov 20, 2023

When I ran with DEBUG flag, I got this at the very end -:

[2023-11-20T04:32:28.245220381Z INFO  py_spy::python_spy] Getting version from python binary BSS
[2023-11-20T04:32:28.245279172Z INFO  py_spy::python_spy] Failed to get version from BSS section: failed to find version string
[2023-11-20T04:32:28.245294131Z INFO  py_spy::python_spy] Trying to get version from path: /usr/bin/qemu-x86_64
Error: Failed to find python version from target process

I am running this within a Docker container and Python 3.8.17 and Apple M1 Chip.

@AcidInvader
Copy link

I'v got the issue: Error: Failed to open process - check if it is running.
when i run this command py-spy record -o profile.svg --pid 8039. Please help me how can i solve it?

@cemlyn007
Copy link

cemlyn007 commented Jun 17, 2024

With py-spy 0.3.14, in my case, it looks it struggles to get the extract the version from the path:

[2024-06-17T11:12:05.444696000Z INFO  py_spy::python_spy] got symbol Py_GetVersion.version (0x00000001037ae650) from libpython binary
[2024-06-17T11:12:05.444702000Z INFO  py_spy::python_spy] Getting version from symbol address
[2024-06-17T11:12:05.444717000Z INFO  py_spy::python_spy] Getting version from python binary BSS
[2024-06-17T11:12:05.444720000Z INFO  py_spy::python_spy] Failed to get version from BSS section: failed to find version string
[2024-06-17T11:12:05.444722000Z INFO  py_spy::python_spy] Getting version from libpython BSS
[2024-06-17T11:12:05.444732000Z INFO  py_spy::python_spy] Failed to get version from libpython BSS section: failed to find version string
[2024-06-17T11:12:05.444733000Z INFO  py_spy::python_spy] Trying to get version from path: /opt/homebrew/Cellar/[email protected]/3.10.14/Frameworks/Python.framework/Versions/3.10/Resources/Python.app/Contents/MacOS/Python

@mrjazz
Copy link

mrjazz commented Jul 27, 2024

Have the same problem, py-spy version is 0.3.14, MacOS version is Sonnoma 14.5

@aditya-sengupta
Copy link

Same problem, py-spy 0.3.14, MacOS Ventura 13.2.1

@amenasria
Copy link

amenasria commented Jan 31, 2025

For macOS folks, just spent 3 hours debugging this 🫡 Here's how I fixed it:

TL; DR: I uninstalled the Python I installed through brew or the Python installer (because they might be conflict with reading memory from those) and used pyenv to install a local python (see script below). After that it worked !

# Uninstall other Python binaries through brew or rm
brew uninstall [email protected]
# Setup pyenv
brew update
brew install pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc
#  Restart your shell
exec "$SHELL"
# Install Python
pyenv install 3.11.8
# Use it globally
pyenv global 3.11.8

Longer explanation (from this section of py-spy README): macOS SIP is preventing all users from reading memory from any binary located in protected directories (such as /usr/bin maybe containing your Python binary). So you should either:

  • disable SIP (kinda risky),
  • install a Python that won't be protected by SIP(recommended).

Hope this helped !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests