在Linux系统中,可以使用pip工具来安装第三方Python库
首先,确保你已经安装了pip。如果没有,请按照以下步骤安装:
对于基于Debian的系统(如Ubuntu):
sudo apt-get update sudo apt-get install python3-pip 对于基于RPM的系统(如Fedora、CentOS):
sudo yum install python3-pip 使用pip安装第三方库。例如,如果你想安装名为requests的库,请执行以下命令:
pip3 install requests 这将自动下载并安装requests库及其依赖项。
安装完成后,你可以在Python脚本中使用新安装的库。例如:
import requests response = requests.get('https://api.example.com/data') print(response.text) 注意:在某些Linux发行版中,可能需要使用pip3而不是pip来安装Python 3的库。请根据你的系统环境选择合适的命令。