All Products
Search
Document Center

Alibaba Cloud SDK:Build a Python development environment on Windows

Last Updated:Feb 28, 2026

Set up PyCharm on Windows and run your first Alibaba Cloud SDK or API call.

Prerequisites

Before you begin, make sure that you have:

Install PyCharm

  1. Go to the PyCharm download page and click Download.

    image

  2. Find PyCharm Community Edition and click Download.

    image

  3. Double-click the downloaded installation file (pycharm-community-2024.1.1.exe) and follow the wizard to complete the installation.

    Important

    In the Installation Options step, select Add the bin folder to PATH.

Create a project

  1. Open PyCharm and click New Project.

    image

  2. In the New Project dialog box, configure the following settings:

    • Name: Enter a project name. Example: pythonProject.

    • Location: Specify where to save the project files.

    Note

    Create Git repository creates a Git repository for version control. This option is not selected in this example.

    Create a welcome script creates a main.py file. This option is not selected in this example.

  3. For Interpreter type, select one of the following options:

    • Project venv (used in this example): Creates a virtual environment that isolates project dependencies from the system Python interpreter. This option suits most Python projects. Python version defaults to the installed Python version. If multiple versions are installed, select the one to use. image

    • Base conda: Uses the conda cross-platform environment manager. This option suits multi-language development in complex environments.

    • Custom environment: Manually create and configure a Python environment.

      Note

      Inherit packages from base interpreter makes third-party libraries from the global interpreter available in this environment.

      Make available to all projects shares the libraries installed in this environment with all projects.

      image

      • Environment: Generate new creates a new environment. Select existing uses an existing one.

      • Type: The environment type. Virtualenv is selected by default.

      • Base python: The Python interpreter version.

      • Location: Where to save the Python environment.

Create and run a Python file

  1. Right-click the project name and choose New > Python File. Enter a file name, select Python file, and press Enter. This example creates a file named hello_aliyun.py.

    image

    image

  2. In the editor, enter print("hello aliyun!") and click the Run icon in the upper-right corner. The output hello aliyun! appears in the Run window at the bottom of the console.

    image

Use the terminal for Python and pip commands

Click the Terminal icon at the bottom of the PyCharm console, or press Alt+F12, to open the built-in command-line interface (CLI). The terminal supports most commands, including python to run scripts and pip install to install third-party libraries.

image

Next steps

After setting up your Python development environment, try the following scenarios to start building with Alibaba Cloud services.

Call Alibaba Cloud API operations with the Python SDK

Use the Alibaba Cloud SDK for Python to call API operations. This example calls the DescribeInstanceTypeFamilies operation of Elastic Compute Service (ECS).

Set up authentication

  1. Get an AccessKey pair. We recommend that you use the AccessKey pair of a Resource Access Management (RAM) user. See Create an AccessKey pair for a RAM user.

    Important

    Configure the AccessKey pair as environment variables. Do not hardcode credentials in your code. For setup instructions, see Configure environment variables in Linux, macOS, and Windows.

Generate and run the SDK sample code

  1. Log on to SDK Center and select the service to call.

  2. On the Parameters tab in the middle column, set the request parameters. Refer to the Document tab in the rightmost column for usage notes, parameter descriptions, and billing information. In this example, the DescribeInstanceTypeFamilies operation has two parameters: Check the Document tab for valid parameter values and configure them based on your requirements.

    • RegionId (required): Set to a value such as cn-qingdao.

    • Generation (optional): Set to a value such as ecs-5 for the V-series instance family.

    image

  3. On the SDK Sample Code tab in the rightmost column, select Python and click Download Project to download the complete SDK project. Decompress the package after downloading.

    image

  4. The downloaded project contains the following sample code:

    # -*- coding: utf-8 -*-
    import os
    import sys
    
    from typing import List
    
    from alibabacloud_ecs20140526.client import Client as Ecs20140526Client
    from alibabacloud_tea_openapi import models as open_api_models
    from alibabacloud_ecs20140526 import models as ecs_20140526_models
    from alibabacloud_tea_util import models as util_models
    from alibabacloud_tea_util.client import Client as UtilClient
    
    
    class Sample:
        def __init__(self):
            pass
    
        @staticmethod
        def create_client() -> Ecs20140526Client:
            """
            Use your AccessKey ID and AccessKey secret to initialize the client.
            @return: Client
            @throws Exception
            """
    
            config = open_api_models.Config(
            # os.environ specifies that the AccessKey ID and AccessKey secret are obtained from an environment variable.
            # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured. ,
            access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
            # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured. ,
            access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
            )
            config.endpoint = f'ecs.cn-qingdao.aliyuncs.com'
            return Ecs20140526Client(config)
    
        @staticmethod
        async def main_async(
                args: List[str],
        ) -> None:
            client = Sample.create_client()
            describe_instance_type_families_request = ecs_20140526_models.DescribeInstanceTypeFamiliesRequest(
                region_id='cn-qingdao',
                generation='ecs-5'
            )
            runtime = util_models.RuntimeOptions()
            try:
                # If you copy and run the sample code, write your own code to display the response of the API operation.
                await client.describe_instance_type_families_with_options_async(describe_instance_type_families_request, runtime)
            except Exception as error:
                # Handle exceptions with caution based on your actual business scenario and do not ignore exceptions in your project. The error message displayed in this example is for reference only.
                # The error message.
                print(error.message)
                # The URL of the corresponding error diagnostics page.
                print(error.data.get("Recommend"))
                UtilClient.assert_as_string(error.message)
    
    
    def main(
            args: List[str],
    ) -> None:
        client = Sample.create_client()
        describe_instance_type_families_request = ecs_20140526_models.DescribeInstanceTypeFamiliesRequest(
            region_id='cn-qingdao',
            generation='ecs-5'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # If you copy and run the sample code, write your own code to display the response of the API operation.
            response = client.describe_instance_type_families_with_options(describe_instance_type_families_request, runtime)
            print(response)
        except Exception as error:
            # Handle exceptions with caution based on your actual business scenario and do not ignore exceptions in your project. The error message displayed in this example is for reference only.
            # The error message.
            print(error.message)
            # The URL of the corresponding error diagnostics page.
            print(error.data.get("Recommend"))
            UtilClient.assert_as_string(error.message)
    
    
    if __name__ == '__main__':
        main(sys.argv[1:])
  5. Run the project to get results similar to the following:

    image

  6. For more details on using the SDK, see Use the Alibaba Cloud Python SDK in an IDE.

Call the Qwen API

Alibaba Cloud Model Studio supports calling large language models (LLMs) through OpenAI-compatible APIs and the DashScope SDK.

Set up authentication

  1. Activate Alibaba Cloud Model Studio and get an API key. See Account Settings.

    Important

    Set the API key as an environment variable to avoid exposing it in your code. See Set API key as environment variable.

Install the SDK and run the sample code

  1. Install the OpenAI Python SDK: If the output includes Successfully installed ... openai-x.x.x, the SDK is installed.

    # If the execution fails, replace pip with pip3 and re-run the command.
    pip install -U openai

    image

  2. Run the following sample code to call the Qwen API:

    import os
    from openai import OpenAI
    
    try:
        client = OpenAI(
            # os.getenv obtains the API key from environment variables. If you have not configured environment variables, replace the following line with your Alibaba Cloud Model Studio API key: api_key="sk-xxx",
            api_key=os.getenv("DASHSCOPE_API_KEY"),
            base_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
        )
    
        completion = client.chat.completions.create(
            model="qwen-plus",
            messages=[
                {'role': 'system', 'content': 'You are a helpful assistant.'},
                {'role': 'user', 'content': 'Who are you?'}
            ]
        )
        print(completion.choices[0].message.content)
    except Exception as e:
        print(f"Error message: {e}")
  3. Expected output:

    image

  4. For more information, see OpenAI Python SDK.

Call the DeepSeek API

Call DeepSeek models through the Alibaba Cloud Model Studio platform. The deepseek-r1 and deepseek-v3 models each offer 1 million free tokens. Some distill models are available for a limited-time free trial.

Set up authentication

  1. Activate Alibaba Cloud Model Studio and get an API key. See Manage account.

    Important

    Set the API key as an environment variable to avoid exposing it in your code. See Configure the API key as an environment variable.

Install the SDK and run the sample code

  1. Install the OpenAI Python SDK: If the output includes Successfully installed ... openai-x.x.x, the SDK is installed.

    # If the execution fails, replace pip with pip3 and re-run the command.
    pip install -U openai

    image

  2. Run the following sample code to call DeepSeek:

    import os
    from openai import OpenAI
    
    client = OpenAI(
        # os.getenv obtains the API key from environment variables. If you have not configured environment variables, replace the following line with your Alibaba Cloud Model Studio API key: api_key="sk-xxx",
        api_key=os.getenv("DASHSCOPE_API_KEY"),
        base_url="https://dashscope.aliyuncs.com/compatible-mode/v1"
    )
    
    completion = client.chat.completions.create(
        model="deepseek-r1",  # This example uses deepseek-r1. Change the model name as needed.
        messages=[
            {'role': 'user', 'content': 'Which is larger, 9.9 or 9.11?'}
        ]
    )
    
    # Print the reasoning process using the reasoning_content field.
    print("Reasoning process:")
    print(completion.choices[0].message.reasoning_content)
    
    # Print the final answer using the content field.
    print("Final answer:")
    print(completion.choices[0].message.content)
  3. Expected output:

    image

  4. Call the DeepSeek API. For more information, see .