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

pidcat installed via brew no longer works on macOS 12.3, due to Python 2 having been removed #180

Open
oscarnylander opened this issue Mar 23, 2022 · 19 comments

Comments

@oscarnylander
Copy link

Hey!

First off, thank you for the great util, Jake. And all the other cool stuff you've built througout the years.

I'm having an issue where pidcat, installed from brew, can no longer run on macOS 12.3. I believe this is because of Python 2 having been removed on this version of macOS.

I'm getting the following output, when attempting to run pidcat:

~ pidcat
zsh: /opt/homebrew/bin/pidcat: bad interpreter: /usr/bin/python: no such file or directory

This in turn is caused by

#!/usr/bin/python -u
:

#!/usr/bin/python -u

On macOS 12.3, /usr/bin/python does not exist - only /usr/bin/python3.

Running on the latest development version (as listed in the current README.md, does not solve the issue, as it still looks for python, which still does not exist.

One alternative that could resolve the issue would be to update pidcat to explicitly try to use python3, but this would have some less desirable backwards compatibility issues, perhaps.

@jox
Copy link

jox commented Mar 24, 2022

Having the same issue here.

Quick hack:

install python 2 via brew: brew install python@2

Then in pidcat.py change

#!/usr/bin/python -u

to

#!/usr/local/Cellar/python@2/2.7.15_1/bin/python2 -u

(Might vary depending on the exact installed version of python 2.)

@oscarnylander
Copy link
Author

The fix applied in #179 makes pidcat work with Python 3. Should that PR be merged, consumers of the script could simply symlink python to python3.

@jox
Copy link

jox commented Mar 25, 2022

Simply symlinking python to python3 isn't a good idea. First of all, it is not "simple" on macOS due to SIP since OS X 10.11. Secondly, it might produce confusion and unexpected results on other ends (e.g. Python things that expect python to be Python 2).

The real solution would be to fully depend Pidcat on Python 3. It's also about time, since Python 2 has long-since reached end of life.

@rlemasquerier
Copy link

Any updates on this ? Should we make pidcat compatible with python 3 and simply replace python link with python3 in pidcat.py ?

@iamwent
Copy link

iamwent commented Apr 20, 2022

I got the same error on my Apple M1.

I installed pidcat 2.1.0 via homebrew and python 3.8 by miniconda.

The error is caused by the first line of local pidcat file(path: /opt/homebrew/Cellar/pidcat/2.1.0/bin/pidcat):

#!/usr/bin/python -u

I just replaced it with: #!/usr/bin/env -S python -u, according to the latest version:

#!/usr/bin/env -S python -u

Don't forget to add write permission to the local pidcat file:

chmod +w /opt/homebrew/Cellar/pidcat/2.1.0/bin/pidcat

@brAzzi64
Copy link

brAzzi64 commented May 2, 2022

I tried installing the latest from master (brew install --HEAD pidcat), verified that the first line of the script is:

#!/usr/bin/env -S python -u

But I still get an error: env: python: No such file or directory when running it.

If I try changing the python in #!/usr/bin/env -S python -u by python3, pidcat runs, but instead of colors, I get lines in the shape of:

b'\x1b[33m GestureDetector\x1b[0m \x1b[30;102m I \x1b[0m obtain mCurrentMotionEventRaw. action: 2 id: 629418386'

Any hints?

@erikhuizinga
Copy link

This might be fixed in #179. It also should fix #178.

@gustavoriveray
Copy link

switching to --HEAD fixed it in a way that you can get logs now, but as the comment above. there's no coloring anymore and the ansi color codes are showing instead as part of the log.

@gustavoriveray
Copy link

OK I actually modified the local file as #179 suggests and the whole thing (get colored pretty logs) works now

@gustavoriveray
Copy link

I used to do the following for getting the logs saved into an html file with colors for sharing

pidcat package | aha --title 'some title' > ~/Desktop/filename.html

After the changes in my comments above I can get colored logs in my terminal but they end in plain black text on the html. Any idea why?

@jiechic
Copy link

jiechic commented May 11, 2022

Having the same issue here.

Quick hack:

install python 2 via brew: brew install python@2

Then in pidcat.py change

#!/usr/bin/python -u

to

#!/usr/local/Cellar/python@2/2.7.15_1/bin/python2 -u

(Might vary depending on the exact installed version of python 2.)

No formulae found in taps.

@rafaelmaeuer
Copy link

rafaelmaeuer commented May 11, 2022

I was able to fix it with following steps:

# Use pyenv to install python2 with:
brew install pyenv
pyenv install 2.7.18
 
# Optionally set it to your global default:
pyenv global 2.7.18
 
# Create Alias in .zshrc
alias python=/Users/<user>/.pyenv/versions/2.7.18/bin/python
 
# Reload shell and test
source .zshrc
python -V

# Edit shebang line of Pidcat script
sudo nano "$(which pidcat)"

# Replace first line:
#!/Users/<user>/.pyenv/versions/2.7.18/bin/python -u

@erawhctim
Copy link

@rafaelmaeuer has the right answer! This worked for me as well, on macOS 12.3.1.

I would recommend creating an alias python2 or python27 or something similar, and keeping python3 as your default python version.

@MalcolmMcFly
Copy link

rafaelmaeuer's solution also worked for me.

@vanniktech
Copy link

I didn't want to set it as a default, neither use an alias and this is my workaround based on rafael's:

# Workarounds for Pidcat.
# https://github.com/JakeWharton/pidcat/issues/180#issuecomment-1124019329
brew install pyenv
pyenv install 2.7.18

# Pidcat.
brew install pidcat

# Change pidcat to use Python 2.7.18
sudo sed -i '1d' "$(which pidcat)"
sudo sed -i "1i #\!$HOME/.pyenv/versions/2.7.18/bin/python -u" "$(which pidcat)"

@Fi5t
Copy link

Fi5t commented Jul 25, 2022

My workaround for Apple M1:

$ chmod +w /opt/homebrew/Cellar/pidcat/HEAD-61cd1ee/bin/pidcat
$ sed -i '' '1 s/python/python3/' /opt/homebrew/Cellar/pidcat/HEAD-61cd1ee/bin/pidcat

🤓

@techygrrrl
Copy link

Similar to Raphael's solution, I used pyenv to install version 2.7.18 and set it as global python:

pyenv install 2.7.18
pyenv global 2.7.18

Then I changed the /usr/local/Cellar/pidcat/<pidcat-version>/bin/pidcat shebang as follows:

#!/usr/bin/env python -u

I used /usr/bin/env python instead of hardcoding the path to a single user so that all the user accounts on my Mac can use it as I use multiple users on my machine.

@deckameron
Copy link

deckameron commented Oct 5, 2022

Hi @brAzzi64! Did you manage to solve this colors issue?

[EDIT]
Just found it! :-)

I tried installing the latest from master (brew install --HEAD pidcat), verified that the first line of the script is:

#!/usr/bin/env -S python -u

But I still get an error: env: python: No such file or directory when running it.

If I try changing the python in #!/usr/bin/env -S python -u by python3, pidcat runs, but instead of colors, I get lines in the shape of:

b'\x1b[33m GestureDetector\x1b[0m \x1b[30;102m I \x1b[0m obtain mCurrentMotionEventRaw. action: 2 id: 629418386'

Any hints?

@annop-np
Copy link

annop-np commented Oct 9, 2023

If anyone still read this; I'm not sure how come this still remains open. But both of the issues are fixed by changing:

  • The first line, to: #!/usr/bin/env -S python3 -u
  • The last line, to: print(linebuf)

The broken color output apparently came from the attempt to convert line buffer to utf8.

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