Forums

Cannot uninstall python package through pip install

Can some help me my disk quota exceeded, and I want to uninstall the packages I installed through pip but the "pip uninstall package_name" does not work.

pip uninstall will only uninstall modules that you have installed. If you try it with packages that are installed by default, it will fail.

dont work!! pls help

What kind of error message do you see?

I'm having the same problem. I installed the numpy package twice on accident, and now it won't let me uninstall it.

What is the complete error message that you get when you try to uninstall it, and what is the command that you're running to do so?

.

ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/shutil.py", line 815, in move
    os.rename(src, real_dst)
OSError: [Errno 18] Invalid cross-device link: '/usr/local/bin/f2py' -> '/tmp/pip-uninstall-mqvmxlpq/f2py'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/pip/_internal/cli/base_command.py", line 167, in exc_logging_wrapper
    status = run_func(*args)
  File "/usr/local/lib/python3.10/site-packages/pip/_internal/commands/uninstall.py", line 98, in run
    uninstall_pathset = req.uninstall(
  File "/usr/local/lib/python3.10/site-packages/pip/_internal/req/req_install.py", line 658, in uninstall
    uninstalled_pathset.remove(auto_confirm, verbose)
  File "/usr/local/lib/python3.10/site-packages/pip/_internal/req/req_uninstall.py", line 373, in remove
    moved.stash(path)
  File "/usr/local/lib/python3.10/site-packages/pip/_internal/req/req_uninstall.py", line 271, in stash
    renames(path, new_path)
  File "/usr/local/lib/python3.10/site-packages/pip/_internal/utils/misc.py", line 311, in renames
    shutil.move(old, new)
  File "/usr/local/lib/python3.10/shutil.py", line 836, in move
    os.unlink(src)
PermissionError: [Errno 13] Permission denied: '/usr/local/bin/f2py'

[edit by admin: formatting]

That appears to be trying to install one of our pre-installed packages rather than something that you installed yourself. What is the underlying problem you're trying to solve? Is something not working when you try to use numpy?

If it was already installed, I didn't know that and it made a copy of numpy. When I imported numpy and tried to run the script I was using it, the console said something about how having duplicates of a package may cause technical difficulties or something like that.

OK. Do those errors still appear?

Yep, same error. When I try to run this code:

import numpy

week1 = numpy.array([3, 2, 5, 4, 2, 3, 1])
week2 = numpy.array([4, 4, 6, 5, 7, 3, 4])
week3 = numpy.array([3, 5, 8, 4, 9, 7, 4])
week4 = numpy.array([2, 8, 4, 7, 3, 10, 3])

I get this:

/home/NoThInGnEsS/miscellaneous.py:1: UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged.
  import numpy

[edit by admin: formatting]

I think that error is misleading -- if I understand correctly, you're running your numpy code from our editor. It keeps a console open between runs so that you don't have to wait for a fresh one to start each time. So that means that the first time you run it, numpy is imported. The second time you run it, we flush out all of the existing stuff from that Python process's memory as far as we can, and run your code again -- but I think that numpy is somehow keeping track of the fact that it was previously imported and printing that message.

Is your code actually running, despite that error?

It depends. Sometimes I have to run it few times, sometimes just once, and sometimes it won't work at all.

The proven way to handle problems like that is to save your code in the editor and run it in the bash console with command like python3.10 foobar.py where foobar.py is a file with your script.