Mac OSX, p4 command line and Sublime Text 2

Last week I received a message from one of my Perforce plugin user who had issues on Mac OSX. It seemed like p4 was not found on the system. After some reading and changes to the plugin, I’m glad to say it works now.

I am not a Mac user, never owned one, so my knowledge of OSX is very limited. The solution I’m exposing here might not be the right, if you have better ways to solve this please comment or contact me directly.

First, lets start by installing p4. Since p4 isn’t released as a dmg, I wasn’t sure where to install it. /Applications/Utilities seemed to be a good choice as Terminal was there too. After copying the file, you must make it executable:

sudo chmod +x /full_path_to/p4

You also want your PATH to include the directory where p4 resides. You can do this by modifying your .bash_profile. While adding the p4 path to your .bash_profile, you can also add the variables required to properly use p4 which are P4PORT, P4CLIENT and P4USER (change the values based on your setup):

export P4_HOME=/Applications/Utilities
PATH=${P4_HOME}:${PATH}
export P4PORT=perforce-server:1666
export P4CLIENT=myclientspec
export P4USER=myuser

We’re almost done!

The last part required changes in the code calling p4. For some reason, the environment variables from bash_profile were not propagated when calling the subprocess from Python, adding a call to

source ~/.bash_profile &&

whenever calling p4 fixed the issue, thanks to Phillip Koebbe!

5 thoughts on “Mac OSX, p4 command line and Sublime Text 2

  1. Jonathan says:

    This does not seem to be working for me in OS X 10.7.4. I threw some print statements in Perforce.py to see what was happening and it looks like the “source .bash_profile” is added to the command, however it is not actually affecting the path.

    [print command] source ~/.bash_profile && echo $PATH && p4 info
    [print result] /usr/bin:/bin:/usr/sbin:/sbin

    Perforce [warning]: /bin/sh: p4: command not found
    Perforce [warning]: File is not under the client root

    I also modified WarnUser as below to always print warnings to the console:
    if(perforce_settings.get(‘perforce_log_warnings_to_status’)):
    sublime.status_message(“Perforce [warning]: ” + message)
    print “Perforce [warning]: ” + message

  2. PJ says:

    Thanks for this post, I finally got this working …

    the key for me was these settings:

    export P4_HOME=/Applications/Utilities
    PATH=${P4_HOME}:${PATH}

    without both settings i still get these errors …

    Perforce [warning]: /bin/sh: p4: command not found
    Perforce [warning]: File is not under the client root.

    the default for the plugin is to write messages to the status bar which only shows the last messages and is very misleading since the main error is that p4 is not found, this should be more obvious fatal error not a warning about client root.

    i suspect it is not respecting my `$PATH` variable since it should already be included by default in `/usr/local/bin`
    why it needs to be set again? i have no idea, i’m just glad it’s working :-/

  3. Nathan Barr says:

    I was stuck on the “Perforce [warning]: File is not under the client root” issue for a while and finally figured out the solution for me. Posting here for anyone else who lands here. I was trying to add the config to ~/.profile …That didn’t work. Only ~/.bash_profile works. Also, I only added:

    export P4_HOME=/usr/local/bin/
    PATH=${P4_HOME}:${PATH}
    export P4CONFIG=.p4config

    And then added a .p4config file in my project directory to set the client:

    P4CLIENT=my-client-name

    Now Sublime Perforce Plugin works on OS X Mountain Lion for me!

  4. Geoff Schemmel says:

    Two issues that took me a while to figure out:

    1) Macs will actually use ~/.profile, but only if ~/.bash_profile does not exist. Since I had some config in ~/.profile already, following the ~/.bash_profile suggestion broke a lot of things until I wholesale moved this config to ~/.bash_profile.
    2) Trying to save a file that has not been changed does not auto-checkout a file, and it results in a pop-up error that’s the same as when the plugin isn’t working (non-writable file). It took me a while to realize I had the correct setup.

  5. Eric says:

    Thank you very much Geoff!

    I’ll try to improve this on the next iteration of the plugin! 🙂 Thanks again!

Leave a Reply

Your email address will not be published. Required fields are marked *