简体   繁体   English

如何删除通过 pyenv/pip 安装的包

[英]How to remove a package installed via pyenv/pip

I have a confusing situation with executables on path that were installed via pyenv/pip.我对通过 pyenv/pip 安装的路径上的可执行文件感到困惑。 The story starts with me having multiple python interpreters with a given package.故事开始于我有多个 python 解释器和一个给定的包。 Today I have learned about pipx , which is supposed to provide me with a system-independent executable made of python package (executable).今天我了解了pipx ,它应该为我提供一个由 py​​thon 包(可执行文件)组成的独立于系统的可执行文件。 After installing the package, pipx correctly warns me that it already exists.安装软件包后,pipx 正确警告我它已经存在。 However, it is less clear how to get rid of it on my path to be able to use the new, correct executable.但是,不太清楚如何在我的路径上摆脱它以便能够使用新的、正确的可执行文件。

I have tried literally removing the file on the path that was found as duplicate, which led to a funny situation below:我已经尝试从字面上删除被发现为重复的路径上的文件,这导致了以下有趣的情况:

my_machine:proj_a ikkamens$ pipx install flynt --python python3.8
⚠️  Note: flynt was already on your PATH at /Users/ikkamens/.pyenv/shims/flynt
  installed package flynt 0.40.1, Python 3.8.0
  These apps are now globally available
    - flynt
done! ✨ 🌟 ✨
my_machine:proj_a ikkamens$ flynt --help
pyenv: flynt: command not found

The 'flynt' command exists in these Python versions:
  3.6.8/envs/blues
  3.7.3
  3.8-dev
  blues

my_machine:proj_a ikkamens$ rm /Users/ikkamens/.pyenv/shims/flynt
my_machine:proj_a ikkamens$ flynt
-bash: /Users/ikkamens/.pyenv/shims/flynt: No such file or directory
my_machine:proj_a ikkamens$ cd
my_machine:~ ikkamens$ cat .bashrc | grep fl
my_machine:~ ikkamens$ which flynt
/Users/ikkamens/.local/bin/flynt
my_machine:~ ikkamens$ flynt
-bash: /Users/ikkamens/.pyenv/shims/flynt: No such file or directory

How is it possible that which returns not the same as what is executed?这怎么可能, which回报不一样,执行什么? Note that my .bashrc doesn't contain any alias or similar (grep statement).请注意,我的 .bashrc 不包含任何别名或类似内容(grep 语句)。 how to completely get rid of whatever is left of old installation?如何完全摆脱旧安装留下的任何东西?

As commented by @jordanm, the problem due to bash hashing PATH lookup.正如@jordanm 所评论的,问题是由于 bash 散列 PATH 查找引起的。

my_machine:~ ikkamens$ rm /Users/ikkamens/.pyenv/shims/flynt
my_machine:~ ikkamens$ flynt
-bash: /Users/ikkamens/.pyenv/shims/flynt: No such file or directory
my_machine:~ ikkamens$ which flynt
/Users/ikkamens/.local/bin/flynt
my_machine:~ ikkamens$ hash -r
my_machine:~ ikkamens$ flynt
Running flynt v.0.40.1

With pyenv you have different isolated python environments.使用 pyenv,您可以拥有不同的独立 Python 环境。 First of all you have to activate one of pyenv environments:首先,您必须激活 pyenv 环境之一:

# check which virtual environments you have
pyenv virtualenvs

# activate one
pyenv activate blues
# seems that `blues` is your virtual environment with python 3.6.8
# then install your package into active virtual environment
pip install flynt
# also uninstall packages while being in your environment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM