3

On windows 7 64bit have installed Python 2.7, I have no choice over which version to use.

I have used IDLE to write a script and when I press F5 to run the script everything works as expected.

However, if I double-click the Python file from within explorer or use Py2Exe to make it into an executable the script fails.

This is the part that screws up:

print subprocess.check_output(["git", "pull", "origin", "master"], shell=False)

I keep receiving the git error:

Permission denied (publickey). 
Fatal: the remote end hung up unexpectedly.

As I said, if I open the script in IDLE and run from there it works a charm. I have compared the output of os.environ from both Environments and the output of:

print subprocess.check_output(["ENV"], shell=False)

I can see no differences relating to git inparticular and paths in general. I'm stumped!

PS. If you have a git repo and python installed and a moment to help me then please put the following code in to a file in your git repo:

import sys, subprocess
try:
    print "pulling from github"
    print subprocess.check_output(["git", "pull", "origin", "master"], shell=False)
except:
    print "Failed"
    print sys.exc_info()[0]
raw_input("Any key to exit.")
sys.exit(0)

Right-click on the file and choose "Edit with IDLE" and hit F5. Then try double clicking the .py file directly... What happens for you guys?

Eric Wilson
  • 57,719
  • 77
  • 200
  • 270
Gabe
  • 1,078
  • 1
  • 11
  • 17
  • Did the git server require you to establish an ssh key? (`http://progit.org/book/ch4-3.html`) I have no idea why IDLE would have access to your `id` key file while explorer would not, but the id file is a place to start looking. – Dave Nov 28 '11 at 14:19
  • @Dave Thanks for the reply. The keys are all sorted out, using GitBash I can perform these actions, also when running my Python script from IDLE. Although it would seem when not run under IDLE Git cannot find it's keys. – Gabe Nov 28 '11 at 14:34
  • Please see my reply to user1069471 - when run from IDLE ~/.ssh is checked for a key which works. When not run from IDLE git looks under C:\Program Files (x86)\Git\.ssh where there is no key – Gabe Nov 28 '11 at 15:31
  • 1
    I have tracked the problem down to this: `os.environ['HOME']` does not exist outside IDLE but it does exist inside IDLE. – Gabe Nov 28 '11 at 15:48

1 Answers1

0

Try to run the python script under cmd, make sure the cmd is running in administrator privileges. If this works, try to run it from the explorer with mouse right click->run as administrator, or in the python.exe properties in the Compatibility tab, mark the "Run this program as an administrator" checkbox.

Dolev
  • 86
  • 3
  • Still no luck, running like this Git prompted me to accept the host fingerprint, which means it was running as a different user and also couldn't find the keys anyway. – Gabe Nov 28 '11 at 14:36
  • sorry i posted sample code but it won't work here, edited main comment – Gabe Nov 28 '11 at 14:39
  • I have found the problem. When running via IDLE git checks my home directory .ssh for a private key. When run in other modes it is looking under C:\Program Files (x86)\Git\.ssh and of course there is no key stored there! Does anyone know why? – Gabe Nov 28 '11 at 15:29