Which Python editor has this feature?

Chris Angelico rosuav at gmail.com
Tue Jan 12 05:18:55 EST 2016


On Tue, Jan 12, 2016 at 7:27 PM, Terry Reedy <tjreedy at udel.edu> wrote:
> On 1/11/2016 8:09 PM, Chris Angelico wrote:
>>
>> On Tue, Jan 12, 2016 at 11:55 AM, Bernardo Sulzbach
>> <mafagafogigante at gmail.com> wrote:
>>>
>>> On Mon, Jan 11, 2016 at 10:14 PM, Chris Angelico <rosuav at gmail.com>
>>> wrote:
>>>>
>>>>
>>>> Next IDLE feature request: Can you make it so that, across all
>>>> platforms, it magically installs PostgreSQL and psycopg2? That would
>>>> solve so many of my students' problems...
>
>
> I detect an invisible smiley at the end of that.
>
> PostgresSQL is not a Python package, hence would need a custom script to
> download and invoke, and would probably need user clicks anyway, at least on
> Windows.  Does/could psycopg2 have such for installing its dependency?
>
> Can psycopg2 be installed with pip?  There is an issue (#23551) to make a
> pip GUI and make it accessible from IDLE.  We need someone with both pip and
> tkinter knowledge to either design and write it or mentor a GSOC student to
> do so.  One written, I would add an IDLE menu item to run it, in a separate
> process, just as done now with turtledemo.

Yes, invisible smiley... but with a hint of truth too. Obviously
installing PostgreSQL itself is outside the scope of IDLE, but
psycopg2 is indeed pip-installable... except that it isn't always, on
Windows, because wheels aren't available for all versions. (There's no
Python 3.5 wheel yet; at least, I can't see one on PyPI.) So what I'm
really looking for isn't an IDLE feature but a Python packaging
feature - some people have talked about setting up build farms that
can produce wheels for people.

Hmm. I just tried this, and actually, there's some possibly
low-hanging fruit. (Tested on Python 3.4.3 as 3.5 can't install
psycopg2 anyway.)

>>> import pip; pip.main(["install","psycopg2"])

This produces a rather messy display, because pip.main seems to assume
that writing carriage returns to the console will result in the
display nicely overwriting (producing a moving progress bar as the
file gets downloaded). If IDLE can't handle carriage returns as such,
an easy fix would be to simply display them as complete lines; it
would be more verbose than the normal console behaviour, but not as
ugly.

A couple of other random thoughts from this experiment.

* Going to python.org and pointing the mouse at the download link got
me 3.5.1 32-bit. This is on Google Chrome on a Windows 7 64-bit VM.
* Instead of pip.main(["install","psycopg2"]), I'd like to be able to
say pip.install("psycopg2"). In fact, I might take that to the pip
folks as a suggestion.
* The performance difference between "import pip" on 3.4.3 and 3.5.1
was dramatic! I don't know whether it's CPython that's been sped up or
pip itself, but it's awesome!

There's some kind of issue between pip and Idle that means that
installing a non-wheel blows up with an exception:


Traceback (most recent call last):
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\basecommand.py",
line 211, in main
    status = self.run(options, args)
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\commands\install.py",
line 294, in run
    requirement_set.prepare_files(finder)
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py",
line 334, in prepare_files
    functools.partial(self._prepare_file, finder))
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py",
line 321, in _walk_req_to_install
    more_reqs = handler(req_to_install)
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py",
line 505, in _prepare_file
    abstract_dist.prep_for_dist()
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_set.py",
line 123, in prep_for_dist
    self.req_to_install.run_egg_info()
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\req\req_install.py",
line 410, in run_egg_info
    command_desc='python setup.py egg_info')
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\utils\__init__.py",
line 711, in call_subprocess
    line = console_to_str(proc.stdout.readline())
  File "C:\Users\Rosuav\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pip\compat\__init__.py",
line 47, in console_to_str
    return s.decode(sys.__stdout__.encoding)
AttributeError: 'NoneType' object has no attribute 'encoding'


Maybe calling pip.main just isn't a supported thing, but it'd be nice
if there were _some_ way to do this, even without a fancy GUI.

How much of this is worth doing anything about, and how much is "hey,
you're hacking around calling a command-line tool from inside a GUI,
and stuff ain't a'gonna work right"?

ChrisA



More information about the Python-list mailing list