import pip and Python 3 fun

The Python preferred installer program, pip, allows "easy" installation of third-party modules, like a current favorite pyperclip.

There differences of opinion on what pip stands for. :-)

Unfortunately starting pip in each environment is annoyingly different. See WINDOWS PIP

So why not import pip and run the main() function from the IDLE environment ?

Well, the designer didn't really test that, so PIP goes BOOM when called IDLE , but we can fix it!

Thanks to mahanmarwat (Mahan Marwat) for going here first and leaving a solution for us to work from, see BREADCRUMBS below:

PATCH PIP

So if we patch pip as shown, we CAN get our nice new pyperclip module via pip from IDLE :-)

A patch to pip for execution from IDLE

c:\Program Files (x86)\Python35-32\Lib\site-packages\pip\compat>diff -c RCS\__init__.py __init__.py

*** "RCS\\__init__.py" Wed Nov 16 10:47:42 2016

--- __init__.py Wed Nov 16 10:51:44 2016

***************

*** 70,76 ****

if sys.version_info >= (3,):

def console_to_str(s):

try:

! return s.decode(sys.__stdout__.encoding)

except UnicodeDecodeError:

return s.decode('utf_8')

--- 70,78 ----

if sys.version_info >= (3,):

def console_to_str(s):

try:

! print ("[console_to_str]", s.decode(sys.getdefaultencoding()) )

! return s.decode(sys.getdefaultencoding())

! # return s.decode(sys.__stdout__.encoding)

except UnicodeDecodeError:

return s.decode('utf_8')

c:\Program Files (x86)\Python35-32\Lib\site-packages\pip\compat>

After Patch, we can run pip from IDLE

Remember to exit IDLE (or start another instance).

Don't try to unimport/reload the pip module, as it is complicated in Python 3

(and in Python 2 it was decided it wasn't worth it (five years at least))

YEAH!

WINDOWS PIP:

On a Windows install you might do this to run the pip module from the command line:

(using CMD's TAB Autocomplete to avoid typing those long directory names)

Microsoft Windows [Version 6.3.9600]

(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\student>cd "c:\Program Files (x86)\Python35-32"

c:\Program Files (x86)\Python35-32>

c:\Program Files (x86)\Python35-32>python -m pip help

Usage:

c:\Program Files (x86)\Python35-32\python.exe -m pip <command> [options]

Commands:

install Install packages.

download Download packages.

uninstall Uninstall packages.

freeze Output installed packages in requirements format.

list List installed packages.

show Show information about installed packages.

check Verify installed packages have compatible dependen

cies.

search Search PyPI for packages.

wheel Build wheels from your requirements.

hash Compute hashes of package archives.

completion A helper command used for command completion.

help Show help for commands.

General Options:

-h, --help Show help.

--isolated Run pip in an isolated mode, ignoring

environment variables and user configuration.

-v, --verbose Give more output. Option is additive, and can be

used up to 3 times.

-V, --version Show version and exit.

-q, --quiet Give less output. Option is additive, and can be

used up to 3 times (corresponding to WARNING,

ERROR, and CRITICAL logging levels).

--log <path> Path to a verbose appending log.

--proxy <proxy> Specify a proxy in the form

[user:passwd@]proxy.server:port.

--retries <retries> Maximum number of retries each connection should

attempt (default 5 times).

--timeout <sec> Set the socket timeout (default 15 seconds).

--exists-action <action> Default action when a path already exists:

(s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.

--trusted-host <hostname> Mark this host as trusted, even though it does

not have valid or any HTTPS.

--cert <path> Path to alternate CA bundle.

--client-cert <path> Path to SSL client certificate, a single file

containing the private key and the certificate

in PEM format.

--cache-dir <dir> Store the cache data in <dir>.

--no-cache-dir Disable the cache.

--disable-pip-version-check

Don't periodically check PyPI to determine

whether a new version of pip is available for

download. Implied with --no-index.

c:\Program Files (x86)\Python35-32>pip

'pip' is not recognized as an internal or external command,

operable program or batch file.

c:\Program Files (x86)\Python35-32>REM Darn cannot run pip directly

BREADCRUMBS

Others have had this idea of calling pip from inside programs,

as documented by PYPA

pip assumes sys.__stdout__ has a stream #3356

https://github.com/pypa/pip/issues/3356

and

Can Not Import Pip #1957

https://github.com/pypa/pip/issues/1957

PIP GOES BOOM WHEN CALLED FROM IDLE: