FreeBSD安装Python

1. 说明

目前,FreeBSD 14.0 RELEASE p4 默认安装的是 python 3.9

2. 安装

安装命令:

sudo pkg install python

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    python: 3.9_3,2
    python3: 3_3

Number of packages to be installed: 2

2 KiB to be downloaded.

终端输入 Python 显示:

Python 3.9.18 (main, Dec 19 2023, 01:22:46)
[Clang 16.0.6 (https://github.com/llvm/llvm-project.git llvmorg-16.0.6-0-g7cbf1 on freebsd14
Type "help", "copyright", "credits" or "license" for more information.

查看 Python 默认版本:

python --version

Python 3.9.18

查看 Python 安装路径:

which python

/usr/local/bin/python

安装 pip 工具:

sudo pkg install py39-pip

Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 2 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
    py39-pip: 23.2.1
    py39-setuptools: 63.1.0_1

Number of packages to be installed: 2

The process will require 27 MiB more space.
3 MiB to be downloaded.

3. 其他 Python 版本

sudo pkg install python2

sudo pkg install python27
sudo pkg install py27-pip

sudo pkg install python3

sudo pkg install python37
sudo pkg install py37-pip

sudo pkg install python38
sudo pkg install py38-pip

sudo pkg install python310
sudo pkg install py310-pip

sudo pkg install python311
sudo pkg install py311-pip

建立链接:

ln -s /usr/local/bin/python3.8 /usr/local/bin/python

ln -s /usr/local/bin/pip-3.8 /usr/local/bin/pip

加入环境变量:

vim ~/.bashrc

export PATH=$PATH:.local/bin/

4. 延伸阅读