本文主要介绍了.whl文件的定义,怎么安装.whl文件(离线,在线)。
怎么查看cuda的版本,以及如何安装相应版本的cuda(本地电脑,超算上)
以及如何创建.whl文件
.whl文件的定义
Documentation about compression file formats:
Learn about Compression File Formats and APIs that can open and create archive files
Documentation about WHL file:
WHL File Format - Python Wheel Package File
A WHL (Wheel) file is a distribution package file saved in Python's wheel format. It is a standard format installation of Python distributions andcontains all the files and metadata required for installation . The WHL file also contains information about the Python versions and platforms supported by this wheel file. Similar to an MSI setup file, WHL file format is a ready-to-install format that allows running the installation package without building the source distribution.
.whl
文件是 Python 的一种打包格式,全称为 Wheel 文件。它是一种预编译的二进制分发包,旨在加快和简化 Python 包的安装过程。
.whl
文件本质上是一个 ZIP 压缩包,内部包含了 Python 包的所有必要文件和元数据。与传统的源代码分发包(如 .tar.gz
)不同,Wheel 文件不需要在安装时进行编译,因此安装速度更快,过程更简便。Wheel 文件可以针对不同的操作系统、Python 版本和 CPU 架构进行构建,确保在各种环境下的兼容性。适合在网络受限或无法访问 PyPI 的环境中进行离线安装。
WHL file format is a ZIP (.zip) archive that contains all the installation files and metadata required by installers for installation of a package. These WHL files can be extracted using unzip option or standard decompression software applications such as WinZIP and WinRAR.
A WHL file is named as per the following convention.
{dist}-{version}(-{build})?-{python}-{abi}-{platform}.whl
An example of the WHL file name is as follow.
cryptography-2.9.2-cp35-abi3-macosx_10_9_x86_64.whl
cryptography
is the package name.2.9.2
is the package version of cryptography. A version is a PEP 440-compliant string such as 2.9.2, 3.4, or 3.9.0.a3.cp35
is the Python tag and denotes the Python implementation and version that the wheel demands.(表示python版本)abi3
is the ABI tag. ABI stands for application binary interface.macosx_10_9_x86_64
is the platform tag, which happens to be quite a mouthful.
比如说github上: state-spaces/mamba: Mamba SSM architecture
the core Mamba package:

怎么安装.whl文件
使用 pip
工具可以方便地安装 .whl
文件。
pip install 包名.whl
如果已经下载了 .whl
文件,只需将命令中的 包名.whl
替换为实际的文件名即可。(离线安装)
在安装时,确保所使用的 .whl
文件与当前的 Python 版本和操作系统兼容。
就比如说安装这个mamba_ssm包的时候,可以使用命令
pip install mamba_ssm==1.0.1
或者先把相应的包下载到本地,cd到该包所在的目录下,然后输入命令:
pip install mamba_ssm-1.0.1+cu118torch1.13cxx11abiFALSE-cp39-cp39-linux_x86_64.whl
-
cxx11abi
:指 C++11 ABI,这是 C++ 的一个二进制兼容标准。 -
FALSE
:表示该 wheel(预编译的二进制包)是在不启用新 C++11 ABI 的情况下编译的。 -
cxx11abiFALSE
:使用旧版 ABI(兼容性更好,适合较旧的系统或与其他库链接时避免冲突)。 -
cxx11abiTRUE
:使用新版 C++11 ABI(可能带来性能改进,但需要环境支持)。
怎么查看cuda的版本
cu指的是cuda版本,可以输入以下命令查看cuda的版本:
nvcc --version
电脑可以更新cuda的版本的,可以输入以下命令查看电脑最高支持的cuda版本
nvidia-smi

可以看到我的电脑支持的cuda最高的版本号是12.3。
如果是在超算上,可以使用以下命令查看支持的cuda版本号:
module avail

可以看到这个超算支持的cuda版本号有11.8 12.0 12.1 12.2 12.4 12.6 12.8
安装相应版本的cuda
如果你正好需要cuda12.5版本的,那可以将cuda12.5版本的下载到自己的超算账号上。
首先在官网上找到对应的cuda版本
看到下面的命令了吧?
输入命令:
wget https://developer.download.nvidia.com/compute/cuda/12.5.0/local_installers/cuda_12.5.0_555.42.02_linux.run
chmod +x cuda_12.5.0_555.42.02_linux.run
./cuda_12.5.0_555.42.02_linux.run --silent --toolkit --samples --installpath=/data/home/
sczc338/run/soft/cuda12.5
-
chmod
- 改变文件权限的命令 -
+x
- 添加可执行权限 -
cuda_12.5.0_555.42.02_linux.run
- CUDA安装脚本文件名
这条命令给名为cuda_11.7.0_515.43.04_linux.run
的文件添加可执行权限,使其能够被系统执行。这是必要的,因为下载的安装脚本默认可能没有执行权限。
-
./cuda_12.5.0_555.42.02_linux.run
- 执行当前目录下的CUDA安装脚本 -
--silent
- 以静默模式安装,不显示图形界面,减少用户交互 -
--toolkit
- 安装CUDA Toolkit(核心组件) -
--samples
- 安装CUDA示例代码 -
--installpath=/data/home/sczc338/run/soft/cuda12.5
- 指定CUDA的安装路径
就按照装好了
下面cd到cuda12.5目录下

vi env.sh是在编辑环境脚本
编辑的内容如下:

#!/bin/bash
export CUDA_HOME=/data/home/sczc338/run/soft/cuda12.5
export PATH=$CUDA_HOME/bin:$PATH
export LD_LIBRARY_PATH=$CUDA_HOME/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=$CUDA_HOME/lib:$LIBRARY_PATH
export INCLUDE=$CUDA_HOME/include:$INCLUDE
export CPATH=$CUDA_HOME/include:$CPATH
(按i进入编辑模式,编辑好之后首先按Esc退出键,然后输入 :wq 即可退出)(注意要是英语符号)
使用命令
source /data/home/sczc338/run/soft/cuda12.5/env.sh
即可激活环境(cuda12.5)
如何创建 .whl
文件?
如果你开发了一个 Python 包,并希望将其打包为 .whl
文件,可以按照以下步骤进行::
确保已安装 setuptools
和 wheel
:
pip install setuptools wheel
在包含 setup.py
的项目目录中,运行以下命令:
python setup.py bdist_wheel
执行上述命令后,dist
目录中将生成对应的 .whl
文件。