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

Script fails on macOS 13.2 #25

Open
fseesink opened this issue Feb 13, 2023 · 3 comments
Open

Script fails on macOS 13.2 #25

fseesink opened this issue Feb 13, 2023 · 3 comments

Comments

@fseesink
Copy link

Looking through other issues, guessing this isn't new per se. Looks like this all began as a Python v2 script that's been brought to v3 but still tied to some older modules.

For reference my system:

  • 2019 27" iMac with Core i5 and 32GB RAM
  • macOS 13.2
  • Python.org's Python 3.11.2
  • Command Line Tools for Xcode 14.2

Did a git clone of repo.
First attempt to run script:

% ./mcxToProfile.py 
zsh: ./mcxToProfile.py: bad interpreter: /usr/bin/python: no such file or directory

Looking at file, I see top line shows #!/usr/bin/python. Yeah, that's not gonna work. Modified it to #!/usr/bin/python3 and re-ran script. Now I get

 % ./mcxToProfile.py 
Traceback (most recent call last):
  File "/Users/frank/Desktop/mcxToProfile/./mcxToProfile.py", line 15, in <module>
    from Foundation import NSData, \
ModuleNotFoundError: No module named 'Foundation'

I did some digging and seems that the underbelly of this relies on something called PyObjC. I tried installing it after finding it on PyPi.org, but pip install pyobjc failed miserably.

Found the source code for that here: https://github.com/ronaldoussoren/pyobjc

So cloned it into the directory where I had this script. I setup a virtual environ using virtualenv venv followed by source venv/bin/activate, so I can sandbox this setup somewhat.

At that point I followed the instructions and tried to do python3 pyobjc/install.py but that failed due to not being able to import _install_tool. I moved down into ./pyobjc and re-ran it as python3 install.py, and THAT seemed to do the trick. Got lots of warnings/etc., but it spent the next 20+ minutes compiling. Sadly, that ended badly with

...
                                 ^
      1 error generated.
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> pyobjc-framework-WebKit

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
Installing 'pyobjc-framework-WebKit' failed (status 1)
Cannot build one of the projects, bailing out

So still can't run this.

Anyway, so looks like this "Foundation" module isn't installed, nor can I get the bits going to do so.

If I had to guess, this script relies on features not found on stock macOS systems. Is that a fair assessment? If there are dependencies, might it not help to articulate them in the README.md file so users have a better chance of using this tool? It feels like this could do with a requirements.txt or similar file to let folks know what is expected.

I came here as I was dealing with a Munki issue and multiple references mentioned this particular tool. Sadly looks like it's not quite as simple to use as they made it sound.

@macmule
Copy link

macmule commented Feb 13, 2023 via email

@MehdiYawari
Copy link

I am on macOS Monterey 12.6.3 und have already updated my python to the latest version(3.11.2). But I still get the following error:
Traceback (most recent call last):
File "/Users/taayame4/Desktop/mcxToProfile.py", line 15, in
from Foundation import NSData,
ModuleNotFoundError: No module named 'Foundation'

How do I get any other python3 if not Apple's python3?
Sorry, dont have much experience with the python

@luckman212
Copy link

luckman212 commented Feb 24, 2023

I had to change the shebang from #!/usr/bin/env python to #!/usr/bin/env python3 and make sure to install python@3 from Homebrew — and I think pip install pyobjc to be able to import the Foundation module.

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

4 participants