首页 分类 正文

使用“ pip”卸载软件包还会删除相关软件包吗?

⏱ 阅读约 分钟

问题:使用“ pip”卸载软件包还会删除相关软件包吗?

当您pip用来安装软件包时,所有必需的软件包也会随之安装(依赖关系)。卸载该软件包还会删除从属软件包吗?

When you use pip to install a package, all the required packages will also be installed with it (dependencies). Does uninstalling that package also remove the dependent packages?


回答 0

不,它不会卸载依赖包。它仅删除指定的软件包:

$ pip install specloud
$ pip freeze # all the packages here are dependencies of specloud package

figleaf == 0.6.1
鼻子== 1.1.2
pinocchio == 0.3
specloud == 0.4.5

$ pip uninstall specloud
$ pip freeze

figleaf == 0.6.1
鼻子== 1.1.2
匹诺曹== 0.3

如您所见,这些程序包是来自的依赖项specloud,它们仍然存在,但不是specloud程序包本身。

如下所述,您可以安装并使用pip-autoremove实用程序删除软件包以及未使用的依赖项。

No, it doesn’t uninstall the dependencies packages. It only removes the specified package:

$ pip install specloud
$ pip freeze # all the packages here are dependencies of specloud package

figleaf==0.6.1
nose==1.1.2
pinocchio==0.3
specloud==0.4.5

$ pip uninstall specloud
$ pip freeze

figleaf==0.6.1
nose==1.1.2
pinocchio==0.3

As you can see those packages are dependencies from specloud and they’re still there, but not the specloud package itself.

As mentioned below, You can install and use the pip-autoremove utility to remove a package plus unused dependencies.


回答 1

您可以安装并使用pip-autoremove实用程序删除软件包以及未使用的依赖项。

# install pip-autoremove
pip install pip-autoremove
# remove "somepackage" plus its dependencies:
pip-autoremove somepackage -y

You can install and use the pip-autoremove utility to remove a package plus unused dependencies.

# install pip-autoremove
pip install pip-autoremove
# remove "somepackage" plus its dependencies:
pip-autoremove somepackage -y

回答 2

我已经使用以下bash行成功删除了软件包的依赖项:

for dep in $(pip show somepackage | grep Requires | sed 's/Requires: //g; s/,//g') ; do pip uninstall -y $dep ; done

这在pip 1.5.4上有效

i’ve successfully removed dependencies of a package using this bash line:

for dep in $(pip show somepackage | grep Requires | sed 's/Requires: //g; s/,//g') ; do pip uninstall -y $dep ; done

this worked on pip 1.5.4


回答 3

我发现了解决方案,尽管对于某些人来说可能有点困难。

第一步(适用于python3和linux):
pip3 install pip-autoremove
第二步:
cd /home/usernamegoeshere/.local/bin/
第三步:
gedit /home/usernamegoeshere/.local/lib/python3.8/site-packages/ pip_autoremove.py
并将所有pip更改为pip3第四步:./ pip-autoremove packagenamegoeshere

至少,这是对我有用的…

I have found the solution even though it might be a little difficult for some to carry out.

1st step (for python3 and linux):
pip3 install pip-autoremove
2nd step:
cd /home/usernamegoeshere/.local/bin/
3rd step:
gedit /home/usernamegoeshere/.local/lib/python3.8/site-packages/pip_autoremove.py
and change all pip(s) to pip3 4th step: ./pip-autoremove packagenamegoeshere

At least, this was what worked for me …


回答 4

您可以尝试使用https://github.com/cls1991/pef。它将删除软件包及其所有依赖项。

You may have a try for https://github.com/cls1991/pef. It will remove package with its all dependencies.


🏷️ 标签

📖 相关文章


Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /www/wwwroot/pythondict/wp-content/plugins/wp-performance/vendor/matthiasmullie/minify/src/CSS.php:528 Stack trace: #0 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/vendor/matthiasmullie/minify/src/CSS.php(528): implode() #1 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/vendor/matthiasmullie/minify/src/CSS.php(314): MatthiasMullie\Minify\CSS->shortenColors() #2 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/vendor/matthiasmullie/minify/src/Minify.php(111): MatthiasMullie\Minify\CSS->execute() #3 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/includes/classes/minify.php(29): MatthiasMullie\Minify\Minify->minify() #4 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/includes/classes/parser.php(176): WPP\Minify::code() #5 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/includes/classes/parser.php(113): WPP\Parser->parseCSS() #6 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/includes/classes/parser.php(35): WPP\Parser->parseTemplate() #7 /www/wwwroot/pythondict/wp-content/plugins/wp-performance/includes/classes/parser.php(60): WPP\Parser->__construct() #8 [internal function]: WPP\Parser::init() #9 /www/wwwroot/pythondict/wp-includes/functions.php(5481): ob_end_flush() #10 /www/wwwroot/pythondict/wp-includes/class-wp-hook.php(341): wp_ob_end_flush_all() #11 /www/wwwroot/pythondict/wp-includes/class-wp-hook.php(365): WP_Hook->apply_filters() #12 /www/wwwroot/pythondict/wp-includes/plugin.php(522): WP_Hook->do_action() #13 /www/wwwroot/pythondict/wp-includes/load.php(1308): do_action() #14 [internal function]: shutdown_action_hook() #15 {main} thrown in /www/wwwroot/pythondict/wp-content/plugins/wp-performance/vendor/matthiasmullie/minify/src/CSS.php on line 528