Replacement for %pip
See original GitHub issueProblem
- The %pip that comes with IPython doesn’t work with jupyterlite as there is no shell.
- 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:
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?
For a potential solution: went the other way on this on #832, rewriting
%pip
toawait __import__('piplite').install
.