本教程提供了有关如何安装 python 以通过 .NET 运行 Aspose.Slides for Python 的详细步骤。假设您在任何基于 Microsoft Windows、macOS 或 Linux 的系统中配置了 .NET Framework,并指导您安装在 Python 中运行 Aspose.Slides 代码所需的所有必要软件。我们将在这些步骤中安装 Python 并创建一个新的 PPTX 文件来验证已建立的环境。
通过 .NET 安装 Python 以运行 Aspose.Slides for Python 的步骤
- 假设您拥有配置了 .NET 框架支持的 Microsoft Windows、macOS 或 Linux。如需更多信息,您可以访问 Install .NET on Windows, Linux, and macOS
- 在 VS Code 中安装 Python 扩展
- 安装 Python 3.9.6
- 安装 Pip 命令
- 安装 Aspose.Slides for Python via .NET
- 编写代码并执行 Aspose.Slides for Python 代码以创建 PowerPoint 文件
如果您的环境满足前两个步骤,则可以忽略它们并在 Linux、Windows 或 macOS 环境中的终端或命令提示符中执行后续命令。您需要安装 Python 和 Pip3 才能安装 Aspose.Slides。
通过 .NET 安装 Python 以运行 Aspose.Slides for Python 的脚本
1. Install .NET Framework (Required for Ubuntu only) | |
#For Ubuntu | |
apt update | |
apt upgrade | |
apt install sudo | |
sudo apt update | |
sudo apt install wget | |
wget -q https://packages.microsoft.com/config/ubuntu/19.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb | |
sudo dpkg -i packages-microsoft-prod.deb | |
sudo apt-get update | |
sudo apt-get install apt-transport-https | |
sudo apt-get update | |
sudo apt-get install dotnet-sdk-3.1 | |
2. Install Python 3.9.6 | |
#For Ubuntu | |
sudo apt install -y python3.9 | |
# For MS Windows and macOS | |
install using MSI or DMG package. Be sure to select the check box to set the path during installation | |
3. Installing Pip Command | |
# For Ubuntu | |
sudo apt install python3-pip | |
# For Windows and Mac | |
python3 -m pip install --upgrade pip | |
4. Install Aspose.Slides | |
python3 -m pip install aspose-slides | |
# Additional requirements for Ubuntu to install libgdiplus and libc6-dev | |
# For Ubuntu only | |
apt-get update | |
apt-get install -y libgdiplus | |
cd /usr/lib && ln -s libgdiplus.so gdiplus.dll | |
apt-get install -y --no-install-recommends libc6-dev | |
5. Write Sample Program and save It As SamplePresentation.Py And Run Program | |
python3 SamplePresentation.py | |
import aspose.slides as slides | |
# Instantiate a Presentation object that represents a presentation file | |
with slides.Presentation() as presentation: | |
slide = presentation.slides[0] | |
slide.shapes.add_auto_shape(slides.ShapeType.LINE, 50, 150, 300, 0) | |
presentation.save("NewPresentation.pptx", slides.export.SaveFormat.PPTX) | |
6. Run the sample using following command | |
python3 SamplePresentation.py |
如果您已经有 .NET、Python 3.9.6 和 PIP 环境设置,您可以从第 4 步开始使用 API。建议使用带有 API 的 Python 3.9.6 而不是旧的 Python2.x。
还提供了一个使用 API 的工作基本示例代码来验证安装。您可以尝试其他示例并探索 API 功能以生成您想要使用 API 生成的不同示例。