All Products
Search
Document Center

Alibaba Cloud SDK:Build a Python development environment on Windows

最終更新日:Jun 24, 2024

This topic describes how to build a Python development environment on Windows. In this example, PyCharm is used.

Procedure

  1. Visit the official website of PyCharm and click Download.

    image

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

    image

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

  4. Open PyCharm and click New Project to create a project for managing software applications or tools that use the Python language.

    image

  5. Enter the project information in the New Project dialog box.

    1. Name: the name of the project. Example: pythonProject.

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

    3. Interpreter type: the runtime environment. In this example, Project venv is selected.

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

        image

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

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

        image

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

    image

    image

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

    image

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.

image