Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Python error adding new repository

Graham Borland October 6, 2011

I'm new to Sourcetree, and I'm trying to open up an existing Mercurial repository. In the main window, I get this error message:

env: python: No such file or directory

I do have Python installed and working. Why is Sourcetree not finding it?

grahamb@pickle:~/Work/repo/dev$ which python
/usr/bin/python
grahamb@pickle:~/Work/repo/dev$ which env
/usr/bin/env
grahamb@pickle:~/Work/repo/dev$ env python
Python 2.6.1 (r261:67515, Aug  2 2010, 20:10:18) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Screenshot

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Graham Borland October 10, 2011

Problem solved! I had in the dim and distant past, installed an Environment Variables plugin to the System Preferences tool. I hadn't realised that adding to my PATH in here was a bad idea. (It edits my environment.plist file, which is apparently where GUI apps get their environment settings from.)

I had also set the path correctly in my .bash_profile, which is why 'env' and 'python' worked fine in the terminal.

Solved by removing the PATH entry from environment.plist. Sourcetree now runs just fine without my local edits.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 10, 2011

Awesome, that explains everything. Thanks for letting us know!

akash.keshari September 24, 2020

@Graham Borland1  @stevestreeting Can you elaborate this answer please as I am not getting any environment.plist file.

I am using Mac OS Catalina 10.15.4 and I am having problems with source tree as I am getting the same error as you.

akash.keshari September 24, 2020

Screenshot 2020-09-24 at 10.32.31 PM.png

1 vote
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2011

That's the standard Python location (it's where mine is) so this should work, however on the Mac the PATH is different for apps than it is for the console, perhaps yours has changed so that /usr/bin is not on it.

The PATH for Mac apps is derived from 2 places (and not the PATH variable):

  • /etc/paths
  • /etc/paths.d/*

So to determine what paths are present for apps, you should do this:

cat /etc/paths
find /etc/paths.d/* -exec cat {} \;

For example, mine looks like this:

Steves-Mac:~ steve$ cat /etc/paths
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin
Steves-Mac:~ steve$ find /etc/paths.d/* -exec cat {} \;
/usr/local/MacGPG2/bin
/usr/X11/bin
/usr/local/git/bin

Graham Borland October 6, 2011

Thanks, but /usr/bin is present in /etc/paths. Any more suggestions?

0 votes
Pablo Diaz-Gutierrez
Contributor
September 15, 2020

For anyone still looking into this, I solved the issue by telling SourceTree to use the system git, instead of the embedded one. Under "Preferences/git/Git Version".

akash.keshari September 24, 2020

@Pablo Diaz-Gutierrez I have the same but issue is not resolved.

I am using Mac OS Catalina 10.15.4.

I have attached screenshot in the top. Please check!!

Pablo Diaz-Gutierrez
Contributor
September 24, 2020

Unfortunately I have since upgraded to the macOS 11 Big Sur (beta 8) and the problem is back with a vengeance. I'll try again later; right now I'm just using the command line for 99% of my git work.

Like akash.keshari likes this
akash.keshari September 24, 2020

@Pablo Diaz-Gutierrez Please try and let me know if there is any update for the fix.

Pablo Diaz-Gutierrez
Contributor
September 24, 2020

Ok, I took another look and the new workaround is to edit the pre-commit hook file. So if you open `.git/hooks/pre-commit` or `.git/modules/SUBMODULENAME/hooks/pre-commit` in your repository, you see that it uses python3.8 in the first line. However, python3.8 lives on /usr/local/bin (the path that SourceTree ignores), whereas in /usr/bin (the path that SourceTree uses), I have python3.

Therefore, possible fixes:

- Replace python3.8 with python3 in the hook file (I did this), or

- Add the full path to python3.8, as in /usr/local/bin/python3.8

Like akash.keshari likes this
akash.keshari September 24, 2020

@Pablo Diaz-Gutierrez  Both the fixes are working fine. 

Awesome Pablo, Thanks a lot...

I wonder how you can able to debug this and find out the fix, it would be a lot helpful if you can explain that, it would really enhance my debugging skills. ☺️

Like Pablo Diaz-Gutierrez likes this
Pablo Diaz-Gutierrez
Contributor
September 24, 2020

I just looked for mentions of "python3.8" in all my .git folder structure, found that one, and started fiddling around, looking for ways in which that I could modify the script to make things work.

Good luck!

Like akash.keshari likes this
akash.keshari September 24, 2020

Nice to hear that... Thanks again..

 

Good luck to you as well.

0 votes
stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2011

If you run the below on the command line, what do you get?

/usr/bin/env python

This is the command at the top of the 'hg' script which appears to be failing in your case, although I've never heard of that before.

Graham Borland October 6, 2011

I get exactly the same Python output as I posted in the question.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2011

Doh, sorry I missed that.

I'm at a loss, if env and python are on your /etc/paths this should work. I'd quite like to see a screenshot of the error in case that helps.

Also, have you changed which Mercurial you're using in Preferences (if you have Mercurial installed separately)?

Graham Borland October 6, 2011

Screenshot uploaded. I haven't changed any options from the default. I tried resetting to the embedded Mercurial, just to be safe, but that has no effect. I do have hg installed in /usr/local/bin via Homebrew, but Sourcetree can't find that one since it's not in the app path.

Graham Borland October 6, 2011

I also just noticed that the Sourcetree icon in my Applications folder still has a 0 overlaid, as if it hasn't been fully installed or activated. During setup, I did allow permission for the app to modify my global settings files.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2011

Firstly, the reason ST can't find your system hg will be because /usr/local/bin isn't in your /etc/paths or /etc/paths.d - ST will find a system hg anywhere so long as it's on the path (for apps, not the console). The trouble with Homebrew is that it installs things in unusual locations and doesn't recognise the existence of anything other than terminals, so you have to tweak things manually if you want GUI apps to pick things up. If you use the standard Mercurial install it'll work out of the box, although Mercurial 1.9 is not supported yet because of a merge crash bug on OS X (this is queued for 1.9.3, I submitted a patch).

About the '0' on the app, this suggests there might be a remaining permissions problem - did you install SourceTree as another user, or in some way that might leave your current user unable to access all of it?

Graham Borland October 6, 2011

I just removed and then re-installted, with exactly the same results. I also get exactly the same result if I run the app directly from the downloaded disk image.

I'll try installing hg to a standard location and see if that helps.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 6, 2011

OK, thanks for trying things - you shouldn't have to though, I test on machines that have never had hg/git installed and it's normally fine.

stevestreeting
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 10, 2011

I'm glad you resolved it, but I have no idea why you needed to do that. Obviously I can't change that in the main package because it wouldn't work on machines where Python was somewhere else (rare, but possible). Using 'env' works for everyone else :/

Graham Borland October 10, 2011

I got it working by changing the hg_local script inside Sourcetree's app directory to call /usr/bin/python directly.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events