4/16/2015

pip.exe runtime error : Python

# Introduction : Fatal error in launcher, Unable to create process using 'C:\Python27\python.exe'   'C:\Python27\Scripts\pip.exe'
This error is because of change in Python environment, to fix it, all you have to do is, tell every program which is not running about this new python environment.

like LINUX command line applications, first line is for program selection, for example,
=> If you are writing a bash script, first line of script will be,
#!/usr/bin/env bash
OR
#!/bin/bash

=> If you are writing a python executable script, first line of script will be,
#!/usr/bin/env python2.7
OR
#!/usr/opt/python27/python2.7
OR
#!/usr/local/bin/python2.7

So, this first line is about, how and using which program, you want to execute it, and where is that program , which you installed.
If you had changed path of this program executable, you also have to tell all your scripts about it, If path to this program is absolute.

#!/usr/bin/env python
This line of code is going to ask  env  program, about absolute location of python executable, if python executable is inside System PATH environment variable (Directories).

# General Solution:-
=> If your python script (like, pip.exe, pip2.exe, easy_install.exe, ipython.exe) do not know about, new location of python interpreter,
then you are going to tell it about python, either by embedding new location of python interpreter or invoking that script with python interpreter.



# Method 1:-
=> Using Python Interpreter (invoke python script with python script executable )
(After adding, python.exe into System PATH environment variable)
You can invoke any python module, using python interpreter, like this

python -m pip install ipython

(select python module named, pip and pass two command line arguments, install, and ipython)

# Method 2:-
=> Using Hex Editor to update new location/path for Python Interpreter.
If all you have is pip.exe (, pip2.exe, easy_install.exe, ipython.exe) instaed of pip.py
then, How your python script knows about python interpreter location/path.
Well, location/path of python interpreter is embeded into it, and you are going to edit it using Hex editor,
A good Hex Editor is Neo Hex Editor, that is Free for personal/limited use.

=> Open  pip.exe using Hex Editor of your choice.
Look for  Python  string inside pip.exe
Program will locate something like this,
#!C:\Python27\python.exe

<Image>
__python_error_before_hex_editing



All you have to do is,
Either change this path to new absolute path to python interpreter.
OR
Edit it like so, (You are telling this script to look for a program name python.exe, which is inside system path environment variable Directories)
#!python.exe


<Image>
__python_error_after_hex_editing


# Method 3:-
=> Using 7zip program to extract __main__.py script from pip.exe (or other similar program, which is showing this runtime error)
=> type __main__.py

# -*- coding: utf-8 -*-
import re
import sys

from pip import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

=> save as this file to pip.py in Script Directory.
=> If you want to invoke this program, use python interpreter.
python pip.py install ipython

=> If you like then you can also create a Batch file ( pip.bat )
@echo off
python %~dp0pip.py %*

# Remember,
%cd%    => expands to current working directory
after expanf   =>  example ,    ( D:\cmder\bin )
%~dp0   => expands to script directory ( where script file in resides on file-system )
after expand   =>  example ,   ( D:\cmder\bin\ )



Post a Comment