Kali安裝pyenv

hirak0發表於2024-04-05

pyenv 可讓您輕鬆地在多個 Python 版本之間切換

安裝依賴

apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev

安裝pyenv

┌──(root㉿MYsec)-[/home/hirak0]
└─# curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2827  100  2827    0     0   1577      0  0:00:01  0:00:01 --:--:--  1577
正克隆到 '/root/.pyenv'...
remote: Enumerating objects: 1243, done.
remote: Counting objects: 100% (1243/1243), done.
remote: Compressing objects: 100% (690/690), done.
remote: Total 1243 (delta 727), reused 708 (delta 420), pack-reused 0
接收物件中: 100% (1243/1243), 618.78 KiB | 1.05 MiB/s, 完成.
處理 delta 中: 100% (727/727), 完成.
正克隆到 '/root/.pyenv/plugins/pyenv-doctor'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 1), reused 5 (delta 0), pack-reused 0
接收物件中: 100% (11/11), 38.72 KiB | 167.00 KiB/s, 完成.
處理 delta 中: 100% (1/1), 完成.
正克隆到 '/root/.pyenv/plugins/pyenv-update'...
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 1), reused 5 (delta 0), pack-reused 0
接收物件中: 100% (10/10), 完成.
處理 delta 中: 100% (1/1), 完成.
正克隆到 '/root/.pyenv/plugins/pyenv-virtualenv'...
remote: Enumerating objects: 63, done.
remote: Counting objects: 100% (63/63), done.
remote: Compressing objects: 100% (56/56), done.
remote: Total 63 (delta 11), reused 29 (delta 0), pack-reused 0
接收物件中: 100% (63/63), 41.13 KiB | 351.00 KiB/s, 完成.
處理 delta 中: 100% (11/11), 完成.

WARNING: seems you still have not added 'pyenv' to the load path.

# Load pyenv automatically by appending
# the following to 
# ~/.bash_profile if it exists, otherwise ~/.profile (for login shells)
# and ~/.bashrc (for interactive shells) :

export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"

# Restart your shell for the changes to take effect.

# Load pyenv-virtualenv automatically by adding
# the following to ~/.bashrc:

eval "$(pyenv virtualenv-init -)"

配置相關Path

把以下內容寫入 ~/.bashrc 並重啟

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

然後執行下面的命令

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.profile
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc

執行下面的命令重新整理

exec "$SHELL"

驗證是否安裝成功

pyenv -h 

出現以下內容說明安裝完成

┌──(root㉿MYsec)-[/home/hirak0]
└─# pyenv -h 
Usage: pyenv <command> [<args>]

Some useful pyenv commands are:
   activate    Activate virtual environment
   commands    List all available pyenv commands
   deactivate   Deactivate virtual environment
   doctor      Verify pyenv installation and development tools to build pythons.
   exec        Run an executable with the selected Python version
   global      Set or show the global Python version(s)
   help        Display help for a command
   hooks       List hook scripts for a given pyenv command
   init        Configure the shell environment for pyenv
   install     Install a Python version using python-build
   latest      Print the latest installed or known version with the given prefix
   local       Set or show the local application-specific Python version(s)
   prefix      Display prefixes for Python versions
   rehash      Rehash pyenv shims (run this after installing executables)
   root        Display the root directory where versions and shims are kept
   shell       Set or show the shell-specific Python version
   shims       List existing pyenv shims
   uninstall   Uninstall Python versions
   update      Update pyenv, its plugins including the list of available versions
   --version   Display the version of pyenv
   version     Show the current Python version(s) and its origin
   version-file   Detect the file that sets the current pyenv version
   version-name   Show the current Python version
   version-origin   Explain how the current Python version is set
   versions    List all Python versions available to pyenv
   virtualenv   Create a Python virtualenv using the pyenv-virtualenv plugin
   virtualenv-delete   Uninstall a specific Python virtualenv
   virtualenv-init   Configure the shell environment for pyenv-virtualenv
   virtualenv-prefix   Display real_prefix for a Python virtualenv version
   virtualenvs   List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
   whence      List all Python versions that contain the given executable
   which       Display the full path to an executable

See `pyenv help <command>' for information on a specific command.
For full documentation, see: https://github.com/pyenv/pyenv#readme  

pyenv命令說明

使用方法:pyenv <command> [<args>]
 
activate     啟用虛擬環境
commands     列出所有可用的pyenv命令
deactivate     停用虛擬環境
doctor     驗證pyenv安裝以及構建Python所需的開發工具。
exec     使用所選的Python版本執行可執行檔案
global     設定或顯示全域性Python版本
help     顯示命令的幫助資訊
hooks     列出給定pyenv命令的鉤子指令碼
init     配置shell環境以使用pyenv
install     使用python-build安裝Python版本
latest     列印已安裝或已知版本的最新版本(具有給定字首)
local     設定或顯示應用程式特定的本地Python版本
prefix     顯示Python版本的字首
rehash     重新生成pyenv shims(在安裝可執行檔案後執行此命令)
root     顯示儲存版本和shims的根目錄
shell     設定或顯示特定shell的Python版本
shims     列出現有的pyenv shims
uninstall     解除安裝Python版本
update     更新pyenv及其外掛,包括可用版本列表
--version     顯示pyenv的版本
version     顯示當前Python版本及其來源
version-file     檢測設定當前pyenv版本的檔案
version-name     顯示當前Python版本
version-origin     解釋當前Python版本的設定方式
versions     列出pyenv可用的所有Python版本
virtualenv     使用pyenv-virtualenv外掛建立Python虛擬環境
virtualenv-delete     解除安裝特定的Python虛擬環境
virtualenv-init     配置shell環境以使用pyenv-virtualenv
virtualenv-prefix       顯示Python虛擬環境版本的real_prefix
virtualenvs     列出在$PYENV_ROOT/versions/*中找到的所有Python虛擬環境
whence         列出包含給定可執行檔案的所有Python版本
which         顯示可執行檔案的完整路徑
檢視特定命令的資訊,請使用pyenv help <command>。獲取完整文件,請訪問:https://github.com/pyenv/pyenv#readme

相關文章