当前位置: 首页 > news >正文

【Ubuntu】安装常用软件包

安装java

直接输入java,如果没有安装的话会提醒你输入命令安装,类似

Command 'java' not found, but can be installed with:
sudo apt install jdkxxxxxxxxxxxxxx

然后选一个版本安装就好,我这里选的jdk17,安装完确认一下

ubuntu@VM-4-13-ubuntu:~$ java --version
openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment (build 17.0.12+7-Ubuntu-1ubuntu224.04)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)

安装python3

输入python看他的意思是有python3,输入python3后果然进入shell了,那就ok了。

ubuntu@VM-4-13-ubuntu:~$ python
Command 'python' not found, did you mean:command 'python3' from deb python3command 'python' from deb python-is-python3
ubuntu@VM-4-13-ubuntu:~$ python3
Python 3.12.3 (main, Apr 10 2024, 05:33:47) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

下面那句是你想要输入python时候就运行python3,可以安装 python-is-python3包,安装后输入python就也可以了,不过保持着能运行就不动原则,我没有操作这个,这步可选
sudo apt install python-is-python3

安装pip

发现pip和pip3也没有,自动提示了安装的命令,还挺方便的

ubuntu@VM-4-13-ubuntu:~$ pip
Command 'pip' not found, but can be installed with:
sudo apt install python3-pip
ubuntu@VM-4-13-ubuntu:~$ pip3
Command 'pip3' not found, but can be installed with:
sudo apt install python3-pip
ubuntu@VM-4-13-ubuntu:~$ 

运行提示的 sudo apt install python3-pip 就可以了,发现pip和pip3都存在,并不是指向一个命令,输入pip list/pip3 list 都没什么问题

ubuntu@VM-4-13-ubuntu:~$ which pip
/usr/bin/pip
ubuntu@VM-4-13-ubuntu:~$ which pip3
/usr/bin/pip3
ubuntu@VM-4-13-ubuntu:~$ ls -lsa /usr/bin/pip
4 -rwxr-xr-x 1 root root 221 Mar  6  2024 /usr/bin/pip
ubuntu@VM-4-13-ubuntu:~$ ls -lsa /usr/bin/pip3
4 -rwxr-xr-x 1 root root 221 Mar  6  2024 /usr/bin/pip3

然后问题就来了,安装时候报错
pip install xxxx

ubuntu@VM-4-13-ubuntu:~$ pip install xxxx
error: externally-managed-environment× This environment is externally managed
╰─> To install Python packages system-wide, try apt installpython3-xyz, where xyz is the package you are trying toinstall.If you wish to install a non-Debian-packaged Python package,create a virtual environment using python3 -m venv path/to/venv.Then use path/to/venv/bin/python and path/to/venv/bin/pip. Makesure you have python3-full installed.If you wish to install a non-Debian packaged Python application,it may be easiest to use pipx install xyz, which will manage avirtual environment for you. Make sure you have pipx installed.See /usr/share/doc/python3.12/README.venv for more information.

解释一下

这个错误信息是 Python 在 Ubuntu 系统上对于系统级包管理的保护机制。从 Python 3.7 开始,Python 包管理器 pip 被设计为默认不安装包到系统级路径,以避免潜在的系统冲突和安全问题。这个机制被称为 “externally-managed-environment”。

错误信息提供了几种解决方案:

  • 使用 apt 命令安装系统级 Python 包:
    sudo apt install python3-xyz

  • 创建虚拟环境:
    如果你想要安装的包不是 Debian 官方仓库中的,你可以创建一个虚拟环境。虚拟环境允许你在不影响系统其他部分的情况下安装和管理 Python 包。使用以下命令创建虚拟环境:

    python3 -m venv path/to/venv
    然后激活虚拟环境:

    source path/to/venv/bin/activate
    在虚拟环境中,你可以使用 pip 来安装包,这些包将只在这个虚拟环境中可用。

  • 使用 pipx 管理非 Debian 打包的 Python 应用:
    pipx 是一个工具,用于在隔离的环境中安装和运行 Python 应用程序。它会自动创建虚拟环境。使用以下命令安装 pipx:
    sudo apt install pipx
    pipx install xyz

  • 覆盖系统包:
    如果你确定要覆盖系统包,可以通过添加 --break-system-packages 选项来使用 pip 安装。但这样做可能会破坏你的 Python 安装或操作系统,因此不推荐这样做,除非你非常清楚你在做什么。

看下来还是最后一点最简单啊,哈哈,先按建议的来试试
pip list看了一眼没有pandas

ubuntu@VM-4-13-ubuntu:~$ python3
Python 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>> 
ubuntu@VM-4-13-ubuntu:~$ sudo apt install python3-pandas 
Reading package lists... Done
Building dependency tree... Done
.....
省略安装日志
.....
ubuntu@VM-4-13-ubuntu:~$ 
ubuntu@VM-4-13-ubuntu:~$ pip3 list |grep "pandas"
pandas                2.1.4+dfsg
ubuntu@VM-4-13-ubuntu:~$ 

ok搞定了,再试下最后一种方法,先卸载掉,重新安装一下
pip uninstall pandas
报上面的错,直接加上 –break-system-packages
pip uninstall pandas --break-system-packages
报错,权限不够,加sudo
sudo pip uninstall pandas --break-system-packages
卸载成功,emmm,好像不用重新安装了,–break-system-packages 也挺好用的,另外几种就不测试了,不喜欢维护每个环境

后续再补充…

http://www.lryc.cn/news/434394.html

相关文章:

  • 探索全光网技术 | 全光网产品解决方案整理-(宇洪科技)
  • 资料分析(2)
  • 百元以下蓝牙耳机性价比之王品牌?四大高能性价比机型推荐
  • 考场考生行为检测数据集 7000张 带标注 voc yolo
  • 深度学习算法,该如何深入,举例说明
  • 舵机的原理及应用
  • Nacos与Eureka--微服务注册中心
  • Android 调试桥——ADB
  • 闲鱼放弃成为淘宝复刻版了吗?上线学生专属交易交流版块“学生鱼”频道
  • 【学习笔记11】如何找到twitter中自己的cookie?
  • 新办建筑智能化专项乙级设计资质,郑州企业需要达到哪些要求?
  • 项目管理:项目执行过程中的控制点——基线
  • NVIDIA驱动学习
  • 小小GCD、LCM拿下拿下
  • 如何集成Android平台GB28181设备接入模块?
  • mysql——关于表的增删改查(CRUD)
  • docker 重启容器且修改服务映射端口
  • 智能提取:OfficeImagesExtractor让文档图片提取更简单
  • 【LLM论文日更】| LLM2Vec揭秘大型语言模型的文本嵌入潜能
  • 大模型微调有必要做吗?LoRa还是RAG?
  • 机器人外呼系统如何使用呢?
  • python-月份有几天
  • 1017 Queueing at Bank
  • DPDK 测试说明
  • 上传及接收pdf文件,使用pdfbox读取pdf文件内容
  • 第一个搭建SpringBoot项目(连接mysql)
  • docker部署rabbitMQ 单机版
  • PDF 全文多语言 AI 摘要 API 数据接口
  • 《信息系统安全》课程实验指导
  • Accelerated Soft Error Testing 介绍