12

I tried to remove a package with pip in a Jupyter notebook but it never finishes and I have to eventually restart the kernel without it uninstalling. I tried:

!python -m pip uninstall pyserial

I found out why it hangs up. When running it from the command line, it asks whether I want to uninstall with a yes/no required.

Uninstalling pyserial-3.4:
  Would remove:
    c:\Anaconda3\lib\site-packages\pyserial-3.4.dist-info\*
    c:\Anaconda3\lib\site-packages\serial\*
    c:\Anaconda3\scripts\miniterm.py
Proceed (y/n)?

Perhaps the confirmation is a new feature of pip? It doesn't seem to be a problem in How to uninstall a package installed with pip install --user. Is there a way to insert a yes response from the Jupyter notebook to not block future cells from running?

Eric Hedengren
  • 455
  • 1
  • 5
  • 19
  • 2
    Does this answer your question? [Bypass Confirmation Prompt for pip uninstall](https://stackoverflow.com/questions/5189199/bypass-confirmation-prompt-for-pip-uninstall) – AMC Feb 07 '20 at 02:14
  • Yes, that answer is close. That question wasn't about the Jupyter notebook appearing to freeze up. I didn't ever get to the `yes`/`no` confirmation so I didn't know what to search to overcome the problem. It may be worthwhile leaving this question if others encounter the same problem in an IPython notebook. – Eric Hedengren Feb 07 '20 at 18:42
  • Thanks! This helped – DonCarleone Oct 06 '21 at 18:44

2 Answers2

28

Try adding --yes to automatically answer the yes/no question.

!python -m pip uninstall pyserial --yes

This uninstalls the package pyserial. You can use the --yes from the command line or in a Jupyter notebook cell.

Uninstalling pyserial-3.4:
  Successfully uninstalled pyserial-3.4
TexasEngineer
  • 684
  • 6
  • 15
0

Not sure about Jupyter notebook but Jupyter lab has a terminal environment that you can access from the Jupyter environment. I made the switch some months back and it was worth it.

ychnh
  • 197
  • 1
  • 12