This topic describes how to build a Python development environment on Windows. In this example, PyCharm is used.
Procedure
Visit the official website of PyCharm and click Download.

On the page that appears, find PyCharm Community Edition and click Download.

Double-click the downloaded installation file named pycharm-community-2024.1.1.exe and follow the installation wizard to install PyCharm.
Important In the Installation Options step, select Add launchers dir to the Path.
Open PyCharm and click New Project to create a project for managing software applications or tools that use the Python language.

Enter the project information in the New Project dialog box.
Name: the name of the project. Example: pythonProject.
Location: the location in which the project files are saved. This allows you to manage 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.
Interpreter type: the runtime environment. In this example, Project venv is selected.
Project venv: creates a virtual environment. A virtual environment isolates the dependencies of the project from the Python interpreter. You can create a separate environment for each project and install the packages and dependencies required by the project in the environment. This option is suitable for most Python projects.
Python version: the version of the Python interpreter. The default value is the version of Python that you have installed. If you have installed multiple versions of Python, you can manually modify the parameter.

Base conda: creates a base conda environment, which is based on the cross-platform environment manager conda and provides more powerful features. This option is suitable for multi-language development projects in complex environments.
Custom environment: creates a custom environment. You can manually create a Python environment and manually install the required packages and dependencies.
Environment: A value of Generate new specifies creating a new environment. A value of Select existing specifies selecting an existing environment.
Type: the type of the environment. Virtualenv is selected by default.
Base python: the version of the Python interpreter.
Location: the location in which the Python environment is saved.
Note Inherit packages from base interpreter: specifies that this environment inherits third-party libraries installed by the global base interpreter.
Make available to all projects: specifies that the third-party libraries installed in this environment apply to all projects.

Right-click the project name and choose New > Python File. In the dialog box that appears, enter the file name, select Python file, and then press the Enter key to create a file. In this example, a file named hello_aliyun.py is created.


In the right-side editor, enter print("hello aliyun!")
and click the Run icon in the upper right corner. You can see the result hello aliyun!
in the Run window in the lower part of the console.

Use python and pip commands
Click the Terminal icon in the lower part of the PyCharm console or press Alt+F12
to open the terminal. The terminal is a built-in CLI in PyCharm that can run most commands. For example, you can use python
commands to execute python files and use pip install
commands to install third-party libraries.

What to do next
After you build a Python development environment, you can use Python to perform various development tasks in different scenarios. Scenarios and procedures:
1. Use Alibaba Cloud SDK for Python to call API operations.
Before you make a call, make sure that an AccessKey pair is obtained. We recommend that you use the AccessKey pair of a Resource Access Management (RAM) user. For more information, see the Create an AccessKey pair for a RAM user section of the "Create an AccessKey pair" topic.
Log on to SDK Center and select the service that you want to use. In this example, the DescribeInstanceTypeFamilies API operation of Elastic Compute Service (ECS) is called.
On the Parameters tab in the middle column, specify the parameters based on your business requirements. When you specify the parameters, read the information on the Document tab in the rightmost column. Make sure that you understand the usage notes of the operation and the description of each parameter. Pay attention to billing-related information. In this example, the DescribeInstanceTypeFamilies operation supports two request parameters. You must specify a value such as cn-qingdao for the RegionId parameter. The Generation parameter is optional. You can set this parameter to ecs-5, which indicates the V-series instance family. You can view the valid values of the parameters on the Document tab. Configure the parameters based on your actual business requirements.
On the SDK Sample Code tab in the rightmost column, select Python as the programming language and click Download Project to download the complete SDK project to your computer. Then, decompress the package.
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:])
Results:
Use Alibaba Cloud SDK for Python. For more information, see Use Alibaba Cloud SDKs for Python in an IDE.
2. Call the Qwen API to start conversations
Alibaba Cloud Model Studio allows you to call large language models (LLMs) by performing API operations. Alibaba Cloud Model Studio is compatible with API operations and the DashScope SDK. Before you make a call, activate Alibaba Cloud Model Studio and obtain the API key. For more information, see Manage account.
Important After you obtain the API key, specify it in the environment variable. Prevent API key leaks, do not expose the API key in the code. For more information, see Set API key as environment variable.
Run the following command to install the SDK for Python:
# If the execution fails, replace pip with pip3 and re-run the command.
pip install -U openai
If you receive the "Successfully installed ... openai-x.x.x
" message, the SDK for Python is installed.
After you install Python and the SDK for Python, you can run the following sample code to call the Qwen API:
import os
from openai import OpenAI
try:
client = OpenAI(
# os.getenv indicates that the API key is obtained from the environment variable. If you do not configure the environment variable, replace the following setting with 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}")
print("Reference: https://help.aliyun.com/zh/model-studio/developer-reference/error-code")
Output:
For more information about how to call the Qwen API, see OpenAI Python SDK.
3. Call the DeepSeek API
This section describes how to call DeepSeek through API calls on Alibaba Cloud Model Studio. deepseek-r1 and deepseek-v3 provide 1 million free tokens. Some of the distillation models are free of charge for a limited period of time.
Before you make a call, activate Alibaba Cloud Model Studio and obtain the API key. For more information, see Manage account.
Important After you obtain the API key, specify it in the environment variable. Prevent API key leaks, do not expose the API key in the code. For more information, see Set API key as environment variable.
Run the following command to install the SDK for Python:
# If the execution fails, replace pip with pip3 and re-run the command.
pip install -U openai
If you receive the "Successfully installed ... openai-x.x.x
" message, the SDK for Python is installed.
After you install Python and the SDK for Python, you can run the following sample code to call the DeepSeek:
import os
from openai import OpenAI
client = OpenAI(
# os.getenv indicates that the API key is obtained from the environment variable. If you do not configure the environment variable, replace the following setting with 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", # In this example, deepseek-r1 is called. You can specify the name of the model that you want to use.
messages=[
{'role': 'user', 'content': Which is larger, 9.9 or 9.11?''}
]
)
# Use the reasoning_content field to print the referencing process.
print("Referencing process:")
print(completion.choices[0].message.reasoning_content)
# Use the content field to print the final answer.
print("Final answer:")
print(completion.choices[0].message.content)
Output:
Call the DeepSeek API. For more information, see .