You can install the OSS Python SDK to manage OSS buckets, upload and download files, manage data, or perform image processing. This topic describes how to install the OSS Python SDK.
Prerequisites
Install Python.
The OSS Python SDK is compatible with Python versions 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, and later.
NoteWhen you install the Python SDK in a Windows environment, make sure that your Visual C++ version is 15.0 or later.
After the installation is complete, run the following command to check the Python version.
python --version
The following example shows a successful response, which indicates that Python 3.8.2 is installed.
Python 3.8.2
Download the SDK
Install python-devel
After you complete the prerequisites, install the python-devel package.
The OSS Python SDK requires crcmod to calculate cyclic redundancy check (CRC) codes. crcmod depends on the Python.h file in the python-devel package. If the Python.h file is missing from your system, the installation of the OSS Python SDK does not fail. However, the installation of the C extension pattern for crcmod fails. If the C extension pattern for crcmod fails to install, the pure Python pattern is used for CRC data validation during file uploads and downloads. The performance of the pure Python pattern is much lower than that of the C extension pattern. This reduces the efficiency of operations such as uploads and downloads.
Windows
When you install Python on Windows, the dependent header files are also installed. You do not need to install python-devel.
macOS
When you install Python on macOS, the dependent header files are also installed. You do not need to install python-devel.
CentOS
Run the following command to install python-devel.
sudo yum install python-devel
RHEL
Run the following command to install python-devel.
sudo yum install python-devel
Fedora
Run the following command to install python-devel.
sudo yum install python-devel
Debian
Run the following command to install python-devel.
sudo apt-get install python-dev
Ubuntu
Run the following command to install python-devel.
sudo apt-get install python-dev
Install the SDK
After you install python-devel, you can install the OSS Python SDK using one of the following methods.
pip
Install pip.
pip is installed by default with Python 2.7.9 or later and Python 3.4 or later.
Run the following command to install the latest version of the OSS Python SDK.
pip install oss2
Source code
Download the latest version of the OSS Python SDK from GitHub. Decompress the package, navigate to the folder, and make sure that the setup.py file exists in the folder.
To download a historical version of the OSS Python SDK, see Historical versions.
Run the following command to install the OSS Python SDK.
python setup.py install
Verify the SDK
After you install the SDK, perform the following steps to verify the installation.
Run the following command to enter the Python environment.
python
Run the following command to check the version of the OSS Python SDK.
import oss2 oss2.__version__
The following example shows a successful response, which indicates that OSS Python SDK 2.18.3 is installed.
'2.18.3'