如何在FreeBSD 12上安装Pip Python包管理器

时间:2020-02-23 14:38:45  来源:igfitidea点击:

在本教程中,我们将研究如何在FreeBSD 12上安装PIP Python Packager Manager .

PIP是一种用于安装和管理在Python中编写的软件包的包管理系统。

有两种方式可以在FreeBSD系统上安装PIP。
我的笔记本电脑上安装了FreeBSD 12:

# freebsd-version
12.0-RELEASE

FreeBSD 12配有Python2.7和Python3.6.

# python
python2.7         python2.7-config  python3.6         python3.6-config  python3.6m        python3.6m-config

我正在使用的默认版本是3.6.
注意 python命令在FreeBSD 12上不可用。

# which python
python: Command not found

我们可以创建Python3.6二进制文件的符号链接 /usr/local/bin/python

# ln -s /usr/local/bin/python3.6 /usr/local/bin/python
# python --version
Python 3.6.6

安装pip py36-pip软件包:

# pkg install py36-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:
	py36-pip: 9.0.3
	py36-setuptools: 40.0.0
Number of packages to be installed: 2
The process will require 21 MiB more space.
6 MiB to be downloaded.
Proceed with this action? [y/N]: y
[1/2] Fetching py36-pip-9.0.3.txz: 100%    6 MiB 308.7kB/s    00:20    
[2/2] Fetching py36-setuptools-40.0.0.txz: 100%  487 KiB 124.6kB/s    00:04    
Checking integrity... done (0 conflicting)
[1/2] Installing py36-setuptools-40.0.0...
[1/2] Extracting py36-setuptools-40.0.0: 100%
[2/2] Installing py36-pip-9.0.3...
[2/2] Extracting py36-pip-9.0.3: 100%
Message from py36-setuptools-40.0.0:
** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *****
  Only /usr/local/bin/easy_install-3.6 script has been installed
  since Python 3.6 is not the default Python version.
** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *****
Message from py36-pip-9.0.3:
============================== !!!! WARNING !!!! ==========================
pip MUST ONLY be used:
 * With the --user flag, OR
 * To install or manage Python packages in virtual environments
Failure to follow this warning can and will result in an inconsistent
system-wide Python environment (LOCALBASE/lib/pythonX.Y/site-packages) and
cause errors.
Avoid using pip as root unless you know what you're doing.
============================== !!!! WARNING !!!! ==========================

为pip-3.6包创建一个符号链接:

# which pip-3.6
/usr/local/bin/pip-3.6
# ln -s /usr/local/bin/pip-3.6 /usr/local/bin/pip
# pip --version 
pip 9.0.3 from /usr/local/lib/python3.6/site-packages (python 3.6)

升级 pip

# pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
    100% |################################| 1.3MB 750kB/s 
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed pip-18.1

测试点用法

$pip install awscli --user

如果将Python软件包与PIP安装为普通用户,则将二进制文件放在下面 .local/bin/将路径添加到路径变量。

$vim ~/.bashrc
export PATH=$PATH:.local/bin/

如果要为Python 2.7安装PIP,请运行:

# pkg install py27-pip