首页 Installation (Python SDK V1)

Installation (Python SDK V1)

更新时间: 2026-01-28 00:17:50

To manage OSS buckets, upload and download files, manage data, or process images, you must first install the OSS Python SDK. This topic describes the installation process.

Prerequisites

  1. 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.

    Note

    For Windows, make sure that your Visual C++ version is 15.0 or later.

  2. After the installation is complete, you can run the following command to check the Python version.

    python --version

    The following example response indicates that Python 3.8.2 is installed.

    Python 3.8.2

Download the SDK

For more information, see OSS API Documentation.

Install python-devel

After you prepare the environment, install the python-devel package.

Note

The OSS Python SDK requires crcmod to perform cyclic redundancy check (CRC) calculations. crcmod depends on the Python.h file, which is included in the python-devel package. If the Python.h file is missing, the OSS Python SDK can still be installed, but the C extension for crcmod will fail to install. If the C extension fails to install, the SDK defaults to a pure Python mode for CRC data validation during uploads and downloads. The pure Python mode is significantly less efficient than the C extension and can slow down operations.

Windows

When you install Python on Windows, the required header files are also installed. You do not need to install python-devel.

macOS

When you install Python on macOS, the required 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 in one of the following ways.

pip

  1. Install pip.

    pip is installed by default with Python 2.7.9 and later, and Python 3.4 and later.

  2. Run the following command to install the latest version of the OSS Python SDK.

    pip install oss2                   

Source code

  1. Download the latest version of the OSS Python SDK from GitHub. Decompress the package, navigate to the package directory, and confirm that the setup.py file is present.

    To download a historical version of the OSS Python SDK, see Historical Versions.

  2. Run the following command to install the OSS Python SDK.

    python setup.py install                   

Verify the SDK

After you install the SDK, follow these steps to verify the installation.

  1. Run the following command to enter the Python environment.

    python
  2. Run the following command to check the OSS Python SDK version.

    import oss2
    oss2.__version__                         

    The following example response indicates that OSS Python SDK 2.18.3 is installed.

    '2.18.3'

FAQ

Error: No module named _crcfunext

Symptoms

Upload and download API calls that use the OSS Python SDK are significantly slower than calls that use other tools, such as ossutil or other SDKs.

Cause

The _crcfunext.so library fails to be generated when crcmod is compiled because its dependency, the Python.h file, is missing from the system. For more information about crcmod, see the crcmod introduction.

Solution

Verify that the C extension for crcmod is installed.

  1. Run the following command to enter the Python environment.

    python
  2. Run the following command to import the _crcfunext C extension module from the crcmod module.

    import crcmod._crcfunext

    The following error message indicates that the C extension for the crcmod library failed to install.

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ImportError: No module named _crcfunext                                 
  3. Choose a solution based on your operating system.

    Windows

    1. Download the crcmod-1.7.win32-py2.7.msi file or another version of the .msi file.

      Note

      The 32-bit version of crcmod is compatible with both 32-bit and 64-bit Windows systems.

    2. Install the .msi file. During the installation, set the installation path for crcmod to the Lib\site-packages folder within your local Python installation path. For example, D:\python\Lib\site-packages\.

    3. After the installation is complete, verify the crcmod installation again.

    Linux

    For Linux systems, if this issue occurs, perform the following steps:

    1. Run the following command to uninstall crcmod.

      pip uninstall crcmod
    2. Install python-devel. For more information, see Install python-devel.

    3. Run the following command to reinstall crcmod.

      pip install crcmod

      If the installation still fails, uninstall crcmod and run the following command to view detailed information about the failure.

      pip install crcmod -v

Error: No module named 'Crypto'

Symptoms

The No module named 'Crypto' error occurs when you run the program.

Cause

The Crypto module does not exist, or a module named crypto exists.

Solution

Check for a Crypto folder in your local Python installation path, for example, D:\python3.9\Lib\site-packages.

  • If the Crypto folder does not exist, run the following command.

    python -m pip install --upgrade setuptools
  • If a crypto folder (with a lowercase c) exists, rename it to Crypto (with an uppercase C) and try to run the program again.

"is not recognized as an internal or external command" error

In a Windows environment, if you receive an error message that a command "is not recognized as an internal or external command", edit the Path environment variable to add the installation paths for Python and pip. The pip installation path is typically the Scripts folder in the Python installation directory. After you edit the environment variable, you may need to restart your computer for the changes to take effect.

Failed to install the OSS Python SDK

If the installation of the OSS Python SDK fails, run the following command to uninstall it and then try to install it again.

pip uninstall oss2            

How to upgrade the OSS Python SDK

Run the following command to upgrade the OSS Python SDK.

 pip install --upgrade oss2

阿里云首页 对象存储 相关技术圈