question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replacement for %pip

See original GitHub issue

Problem

  1. The %pip that comes with IPython doesn’t work with jupyterlite as there is no shell.
  2. ipywidgets is not included, and requires using await micropip.install(). This is confusing for new users because it uses asyncio, and because it isn’t pip

Proposed Solution

If we override %pip, then we can install ipywidgets (and other packages) without having to use asyncio and micropip. This could make many notebooks 100% identical to their regular IPython brothers.

Here is an implementation (although this is my first asyncio code):

from IPython.core.magic import register_line_magic
from IPython.core import magic_arguments
import asyncio

IN_BROWSER = None
try:
    import micropip
    IN_BROWSER = True
except ImportError:
    IN_BROWSER = False

if IN_BROWSER:
    async def pip_install(package):
        try:
            await micropip.install(package)
            return "    Success! Installed %r" % package
        except Exception as exception:
            return "    Failed installing %r: %s" % (package, exception)

    @register_line_magic
    @magic_arguments.magic_arguments()
    @magic_arguments.argument('-q', '--quiet', help='Give less output.', action='store_true')
    @magic_arguments.argument('command', help="Install.", type=str)
    @magic_arguments.argument('packages', nargs="+", type=str, help='Packages to install.')
    def pip(line):
        args = magic_arguments.parse_argstring(pip, line)
        if args.command == "help":
            print("usage: %pip install package1 package2 ...")
        elif args.command == "install":
            print("Installing %s..." % args.packages)
            loop = asyncio.get_running_loop()
            for package in args.packages:
                task = loop.create_task(pip_install(package))
                task.add_done_callback(
                    lambda t: print(t.result()))
        else:
            print("error: command should be: `install`")

If this is a viable solution, where would this code go?

Output examples:

Screenshot from 2021-07-08 15-54-38

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bollwyvlcommented, Jul 8, 2021

This is a good direction, though given how thin the wrapper there is around pip… it supports a lot of options, and a lot of them will be nonsense in this context, as micropip sure as shooting won’t support all of them.

@martinRenou @madhur-tandon thoughts on the relationship to #216, and specifically, where to land this?

0reactions
bollwyvlcommented, Oct 12, 2022

For a potential solution: went the other way on this on #832, rewriting %pip to await __import__('piplite').install.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PIP replacement part of new user-led plan to transform the ...
In terms of a new disability benefit to replace PIP, the Commission proposes a new non-means-tested benefit to cover the extra costs that ......
Read more >
New disability benefit replacing PIP to be rolled out in three ...
The Adult Disability Payment (ADP) will be administered through Social Security Scotland and will replace the Personal Independence Payment (PIP) ...
Read more >
Personal Independence Payment (PIP) - GOV.UK
Disability Living Allowance ( DLA ) is being replaced by PIP for most adults. You'll keep getting DLA if: you're under 16; you...
Read more >
Adult Disability Payment to replace PIP and DLA in Scotland
Personal Independence Payment and Disability Living Allowance has been replaced by Adult Disability ...
Read more >
Proximal Interphalangeal Joint Replacement with Surface ...
Seventy percent were overall satisfied with operation and functional results. The results of surface replacement arthroplasty of the PIP joint ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found