ubuntu

Ubuntu下Python环境怎么搭建

小樊
34
2025-03-24 16:04:03
栏目: 编程语言

在Ubuntu系统下搭建Python环境可以通过多种方式实现,以下是几种常见的方法:

使用Miniconda安装Python环境

  1. 下载并安装Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
  1. 配置环境变量
# 添加了conda export PATH="$HOME/miniconda3/bin:$PATH"
source ~/.bashrc
  1. 创建新的Conda环境
conda create --name myenv python=3.8
  1. 激活新环境
conda activate myenv

使用Anaconda安装Python环境

  1. 下载并安装Anaconda
wget https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh
bash Anaconda3-2024.02-1-Linux-x86_64.sh
  1. 按照提示完成安装

  2. 验证安装

conda -V

使用系统包管理器安装Python

  1. 更新软件包列表
sudo apt update
  1. 安装Python和pip
sudo apt install python3 python3-pip
  1. 验证安装
python3 --version
pip3 --version

使用虚拟环境管理工具(如venv或virtualenv)

  1. 安装venv模块(Python 3.3及以上版本自带):
python3 -m venv myenv
  1. 激活虚拟环境
source myenv/bin/activate
  1. 安装所需库
pip install library_name
  1. 退出虚拟环境
deactivate

以上方法都可以在Ubuntu系统下搭建Python环境,选择哪种方法取决于你的具体需求和偏好。

0
看了该问题的人还看了