Skip to content

Script fails on macOS 13.2 #25

Open

Description

@fseesink

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.

Activity

  1. macmule commented on Feb 13, 2023

    @macmule
  2. MehdiYawari commented on Feb 24, 2023

    @MehdiYawari

    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

  3. luckman212 commented on Feb 24, 2023

    @luckman212

    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.

  4. simX commented on Sep 13, 2025

    @simX

    This project is still being referenced from a Chrome Enterprise and Education help document here: https://support.google.com/chrome/a/answer/9020077

    I briefly ran into this same issue, so I'll go through how I fixed it:

    # install python 3 from homebrew
    brew install python3
    # download this source code
    git clone git@github.com:timsutton/mcxToProfile.git mcx
    cd mcx
    # create a new virtual environment for pyobjc
    /opt/homebrew/bin/python3 -m venv pyobjc-venv
    # install pyobjc in the virtual environment
    pyobjc-venv/bin/pip install pyobjc
    

    Then you need to edit the shebang line at the top of the script to use the virtual environment:
    #!/Users/username/mcx/pyobjc-venv/bin/python3

    Then you can run the script and it should work:
    ./mcxToProfile.py --plist chrome-policies.plist --identifier com.google.Chrome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions