All Products
Search
Document Center

Object Storage Service:Installation

Last Updated:Dec 13, 2023

If you want to manage Object Storage Service (OSS) buckets, upload and download objects, manage data, and perform image processing (IMG), install OSS SDK for Python first. This topic describes how to install OSS SDK for Python.

Preparations

  1. Install Python.

    OSS SDK for Python requires Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, or later.

    Note

    When you install OSS SDK for Python on Windows, make sure that the version of Visual C++ is 15.0 or later.

  2. Run the following command to check the Python version:

    python --version

    The following response indicates that Python 3.8.2 is installed:

    Python 3.8.2

Download OSS SDK for Python

Install python-devel

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

Note

OSS SDK for Python uses the crcmod library to calculate the value of cyclic redundancy check (CRC). The crcmod library depends on the Python.h file in the python-devel package. If the Python.h file does not exist, the installation is not affected, but crcmod extensions in C fail to be installed. In this case, the Python-only mode is used to calculate the value of CRC and perform CRC-64 when you upload and download objects. As a result, operations such as object upload and download are performed in an inefficient manner.

Windows

When you install Python on Windows, the Python.h file is installed together with Python. Therefore, you do not need to install python-devel.

macOS

When you install Python on macOS, the Python.h file is installed together with Python. Therefore, 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 OSS SDK for Python

After you install python-devel, you can use one of the following methods to install OSS SDK for Python:

pip

  1. Install pip.

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

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

    pip install oss2                   

Source code

  1. Visit GitHub to download the latest version of OSS SDK for Python package. Decompress the package and check whether the setup.py file exists in the directory.

    For more information about how to download an earlier version of OSS SDK for Python, see Historical versions.

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

    python setup.py install                   

Verify whether OSS SDK for Python is installed

After you install OSS SDK for Python, perform the following steps to verify whether OSS SDK for Python is installed:

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

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

    import oss2
    oss2.__version__                         

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

    '2.18.3'

FAQ

What do I do if the "No module named _crcfunext" error message is returned?

Problem description

Using OSS SDK for Python to call upload and download operations is much slower than using other tools, such as ossutil or other OSS SDKs.

Causes

When you compile the crcmod library, the _crcfunext.so file depends on the Python.h file. The error occurs because the Python.h file does not exist in the system, which causes the _crcfunext.so file to fail to be generated. For more information about crcmod, see crcmod introduction.

Solutions

You can perform the following steps to check whether the crcmod extensions in C are installed:

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

    python
  2. Run the following command to import the C extension module of _crcfunext in the crcmod module:

    import crcmod._crcfunext

    If the following error message appears, the crcmod extensions in C fail to be installed:

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

    Windows

    1. Download crcmod-1.7.win32-py2.7.msi or a .msi file of a different version.

      Note

      The crcmod library for win32 systems is also compatible with win64 systems.

    2. Install the .msi file and specify the Lib\site-packages directory in the local installation path of Python as the installation path of crcmod. Example: D:\python\Lib\site-packages\.

    3. Perform the preceding steps to check whether the crcmod extensions in C are installed after the .msi file is installed.

    Linux

    For Linux, perform the following steps to resolve the issue:

    1. Run the following command to uninstall the crcmod library:

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

    3. Run the following command to re-install the crcmod library:

      pip install crcmod

      If the crcmod library fails to be installed after you perform the preceding steps, uninstall the crcmod library. Then, run the following command to view the details of the installation failure:

      pip install crcmod -v

What do I do if the No module named 'Crypto' error message is returned?

Problem description

The No module named 'Crypto' error message is returned during program execution.

Causes

No Crypto exists or crypto exists.

Solutions

Check whether Crypto exists in the local installation path of Python, such as D:\python3.9\Lib\site-packages.

  • If Crypto does not exist, run the following command:

    python -m pip install --upgrade setuptools
  • If crypto, whose first letter is in lowercase, exists, change the first letter to uppercase and restart the program.

What do I do if an error message indicating that the command is not an internal or external command is returned?

On Windows, if an error message indicating that the command is not an internal or external command is returned, modify the Path environment variable and add the installation paths of Python and pip to the environment variable. The installation path of pip is the Scripts directory in the installation path of Python. After you modify the Path environment variable, you may need to restart your computer for the environment variables to take effect.

What do I do if OSS SDK for Python failed to be installed?

If OSS SDK for Python failed to be installed, run the following command to uninstall OSS SDK for Python. Then, re-install it.

pip uninstall oss2            

How do I upgrade OSS SDK for Python?

Run the following command to upgrade OSS SDK for Python:

 pip install --upgrade oss2

What to do next

After you install OSS SDK for Python, you need to configure access credentials. For more information, see Configure access credentials.