Kali-Pip3安装虚拟环境

kali-2024版本,搭建python3的虚拟环境,在虚拟环境中可以直接调用pip3,否则在本地环境不太好用。

体感虚拟环境除了个要进入到虚拟环境这个操作,其他倒是和之前无虚拟环境用法一致。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.

If you wish to install a non-Kali-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have pypy3-venv installed.

If you wish to install a non-Kali-packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.

For more information, refer to the following:
* https://www.kali.org/blog/python-externally-managed/
* /usr/share/doc/python3.12/README.venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
#

报错原因如上。
总之是为了避免冲突所以进行了限制。

1. 创建虚拟环境

创建一个虚拟环境,在该虚拟环境中可以自由使用pip进行相关库的安装而不影响系统级别的Python环境。

1
2
sudo apt install python3-env
python3 -venv [虚拟环境名称]

激活虚拟环境

1
source [虚拟环境名称]/bin/activate

进入到虚拟环境进行安装库

1
pip install [库名]

退出虚拟环境

1
deactivate

2. 使用pipx安装应用程序

理论上,本身自己没有进行安装测试。

安装命令行工具或者应用程序,希望全局可用,但不希望干扰到系统的python环境,可以使用pipx,首先安装一个pipx

1
2
3
sudo apt install pipx
pipx ensurepath
pipx install [库名]

虚拟环境如何提高权限

安装相关库的时候,往往需要高权限才能进行相关库的安装。

  • 先进入管理员权限
  • 然后使用source []/bin/activate进入到搭建的虚拟环境中
-------------THE END-------------