Which Python editor has this feature?
Terry Reedy
tjreedy at udel.edu
Wed Jan 13 04:05:18 EST 2016
On 1/12/2016 5:18 AM, Chris Angelico wrote:
> On Tue, Jan 12, 2016 at 7:27 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> 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.)
Maybe someone should give them a prod. It has been 4 months.
http://www.lfd.uci.edu/~gohlke/pythonlibs/
only has psycopg, for 2.6.
> 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.
Building binaries is a rather different issue, certainly on Windows.
> 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"])
https://bugs.python.org/issue23551
has my report of experimenting with directly using pip.main. The main
issue I ran into is that pip creates a cache of 'currently installed
packages' the first time it needs it and never again during the same
process. In other words, pip.main is called exactly once when pip is
run from the command line. Another command from the command line starts
a new process, which makes a new cache. So calling main() repeatedly
may fail due to a stale cache. However, the need to refresh it is
predictable, so reloading the module may work.
> 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.
Currently, Idle sends user code output to the tk Text widget as is,
except for colorizing. There was an issue about changing this, but it
was closed, at least for the time being, as Python allows print to send
output to any file and does not require than stdout be connected to a
'console', and anyway there is no standard for console behavior.
A gui program that runs pip and displays its output would generally
parse output for display in differnet widgets.
>
> 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!
Try with 3.4.4, as I believe its installer should also update to the
most recent pip version.
> 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",
> ...
> return s.decode(sys.__stdout__.encoding)
> AttributeError: 'NoneType' object has no attribute 'encoding'
Assuming that sys.__sydout__ is not None is a bug on pip's part.
Perhaps you could report it to it list or tracker, and point Donald and
whoever to https://docs.python.org/3/library/sys.html#sys.__stdin__
"Note
Under some conditions stdin, stdout and stderr as well as the original
values __stdin__, __stdout__ and __stderr__ can be None. It is usually
the case for Windows GUI apps that aren’t connected to a console and
Python apps started with pythonw."
IDLE is a GUI app that on Windows is started with pythonw.exe. More
relevant, user code is executed in a windowless pythonw process. The
same problem should occur with any IDE that executes user code in a
pythonw process.
A GUI program could work around the bug by setting sys.__stdin__ to an
object with a .encoding attribute. I checked that this can be done.
> 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.
Calling is once during a process is supported, or supposed to be.
If you ran, at the console,
> pythonw.exe -c "import pip; pip.main(['install','psycopg2'])"
the same failure would happen. However, the only indication of failure,
before you checked site-packages and found no psycopg2, would be the
quick return to the console prompt.
> 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"?
On the issue linked above, Donald Stuffit, a (the?) pip maintainer, said
that he wanted there to be a pip Gui, even though he was unlikely to
write it himself. We have identified 3 problems; I believe all can be
worked around. I added your two and the workarounds to the issue.
--
Terry Jan Reedy
More information about the Python-list
mailing list