如何 pip 卸载使用 git 项目 URL 安装的包?
Posted
技术标签:
【中文标题】如何 pip 卸载使用 git 项目 URL 安装的包?【英文标题】:How to pip uninstall a package installed using a git project URL? 【发布时间】:2019-01-04 20:04:00 【问题描述】:我尝试按照 BlueJeans 会议 REST API (https://github.com/bluejeans/api-rest-meetings/tree/master/libs/python) 的安装说明使用命令
pip install git+https://github.com/bluejeans/api-rest-meetings.git@pip-repo
pip freeze
命令确认我已经安装了它:
Kurts-MacBook-Pro-2:~ kurtpeek$ pip freeze
BlueJeansMeetingsRestApi==1.0.0
certifi==2018.4.16
python-dateutil==2.7.3
six==1.11.0
urllib3==1.23
但是,在 iPython shell 中,我无法导入 BlueJeansMeetingsRestApi
:
Kurts-MacBook-Pro-2:~ kurtpeek$ ipython
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import BlueJeansMeetingsRestApi
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-0891de0c20ce> in <module>()
----> 1 import BlueJeansMeetingsRestApi
ModuleNotFoundError: No module named 'BlueJeansMeetingsRestApi'
这是在我的本地环境中,但我也将它安装在 Pipenv 环境中,在这种情况下,我需要提供一个 egg,我通过将 #egg=BlueJeansMeetingsRestApi
附加到 Git 项目 URL 来完成。如果我立即执行此操作,我会得到“已满足要求”:
Kurts-MacBook-Pro-2:~ kurtpeek$ pip install git+https://github.com/bluejeans/api-rest-meetings.git@pip-repo#egg=BlueJeansMeetingsRestApi
Requirement already satisfied: BlueJeansMeetingsRestApi from git+https://github.com/bluejeans/api-rest-meetings.git@pip-repo#egg=BlueJeansMeetingsRestApi in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.0.0)
Requirement already satisfied: urllib3>=1.15 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (1.23)
Requirement already satisfied: six>=1.10 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (1.11.0)
Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (2018.4.16)
Requirement already satisfied: python-dateutil in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (2.7.3)
因此,我想尝试先卸载 BlueJeans 并指定 egg 重新安装它。但是,如果我尝试使用相同的项目 URL 卸载它,我会收到以下错误:
Kurts-MacBook-Pro-2:~ kurtpeek$ pip uninstall git+https://github.com/bluejeans/api-rest-meetings.git@pip-repo
You must give at least one requirement to uninstall (see "pip help uninstall")
顺便说一句,我使用的是 Python 3.7.0(pip
是 pip3
的别名)。
我有两个问题:
-
为什么
import BlueJeansMeetingsRestApi
一开始就不起作用?
如何卸载它?
【问题讨论】:
您是否尝试使用与它安装到的相同版本的 python 导入它?我的意思是看起来你使用的是 3.6.5 版本,如果它安装到 3.7,那么它将看不到它。安装多个版本时,我已经多次遇到这种情况。 ***.com/questions/10919569/… 【参考方案1】:要卸载一个包,只需使用
pip uninstall BlueJeansMeetingsRestApi
如果 IPYTHON 存在一些配置问题,您可能会遇到此类错误。
但是如果你时间不够,我建议你直接使用 python shell 命令 shell,我认为当你尝试将它导入文件时这应该可以工作。
python <filename>.py
请检查并告诉我。
【讨论】:
【参考方案2】:总结CoderRambo 和tgikal 的回复,是的,我能够以这种方式卸载BlueJeansMeetingsRestApi
:
Kurts-MacBook-Pro-2:~ kurtpeek$ pip uninstall BlueJeansMeetingsRestApi
Uninstalling BlueJeansMeetingsRestApi-1.0.0:
Would remove:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/BlueJeansMeetingsRestApi-1.0.0-py3.7.egg-info
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/BlueJeansMeetingsRestApi/*
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/test/*
Proceed (y/n)? y
Successfully uninstalled BlueJeansMeetingsRestApi-1.0.0
然而,问题的根源在于 iPython 在 Python 3.6 上运行,而 BlueJeans 安装在 Python 3.7 上。我通过使用which ipython
确认了这一点:
Kurts-MacBook-Pro-2:~ kurtpeek$ which ipython
/Library/Frameworks/Python.framework/Versions/3.6/bin/ipython
我跑了pip install ipython
,现在它指向Python 3.7:
Kurts-MacBook-Pro-2:~ kurtpeek$ which ipython
/Library/Frameworks/Python.framework/Versions/3.7/bin/ipython
然后我重新安装了 BlueJeans REST API(没有指定鸡蛋),现在我可以导入它了:
Kurts-MacBook-Pro-2:~ kurtpeek$ ipython
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import BlueJeansMeetingsRestApi
In [2]:
【讨论】:
以上是关于如何 pip 卸载使用 git 项目 URL 安装的包?的主要内容,如果未能解决你的问题,请参考以下文章