温馨提示×

centos怎样导入模块

小樊
45
2026-09-15 14:07:14
栏目: 智能运维

你问的“导入模块”可能指几种不同场景,下面分别说明在 CentOS 下常见的“模块导入”方式:


一、Python 导入模块(最常见)

1️⃣ 系统已安装模块

python3
import os
import requests

2️⃣ 安装并导入第三方模块

pip3 install requests
import requests

3️⃣ 导入自定义模块

假设有 mymod.py

# mymod.py
def hello():
    print("hi")

在同级目录:

import mymod
mymod.hello()

二、CentOS 的 module 环境模块(科研/集群常用)

CentOS 常用 Environment Modules

查看可用模块

module avail

加载模块

module load gcc

卸载模块

module unload gcc

查看已加载

module list

如果没有 module 命令:

yum install environment-modules

三、Shell 脚本导入(source)

导入脚本/函数

source ./env.sh

. ./env.sh

四、内核模块(驱动)

查看模块

lsmod

导入(加载)模块

modprobe xxx

insmod xxx.ko

五、Ansible / Playbook 模块(可选)

- name: use module
  yum:
    name: nginx
    state: present

如果你能说明是 Python / Shell / module命令 / 内核 / 其他,我可以给你更精确的答案。

0