Deze zelfstudie biedt gedetailleerde stappen voor het installeren van python om Aspose.Words voor Python uit te voeren via .NET. Het gaat ervan uit dat u .NET Framework hebt geconfigureerd in een van Microsoft Windows, macOS of Linux gebaseerde systemen en begeleidt u bij het installeren van alle benodigde software die nodig is om Aspose.Words-code in Python uit te voeren. Tijdens deze stappen installeer je Python en maak je een nieuw DOCX-bestand aan om de bestaande omgeving te verifiëren.
Stappen om Python te installeren om Aspose.Words voor Python uit te voeren via .NET
- Er wordt aangenomen dat u een Microsoft Windows, macOS of Linux hebt geconfigureerd met .NET framework-ondersteuning. Voor meer informatie kunt u terecht op Install .NET on Windows, Linux, and macOS
- Installeer Python 3.9.6
- Installeer Pip-opdracht
- Installeer Aspose.Words for Python via .NET met behulp van Pip
- Schrijf en voer de Aspose.Words voor Python-code uit om een Word-bestand te maken
Als u een omgeving heeft die voldoet aan de eerste twee stappen, kunt u deze negeren en de volgende opdrachten uitvoeren in de terminal of opdrachtprompt in uw Linux-, Windows- of macOS-omgeving. U moet Python en Pip3 installeren om Aspose.Words te installeren.
Script om Python te installeren om Aspose.Words voor Python uit te voeren via .NET
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 | |
2. Installing Pip Command | |
# For Ubuntu | |
sudo apt install python3-pip | |
# For Windows and Mac | |
python3 -m pip install --upgrade pip | |
3. Install Aspose.Words | |
python3 -m pip install aspose-words | |
# 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 | |
4. Write Sample Program and save It As SampleWord.Py And Run Program | |
python3 SampleWord.py | |
import aspose.words as aw | |
doc = aw.Document() | |
builder = aw.DocumentBuilder(doc) | |
builder.write("Hello world!") | |
doc.save("c:\\words\\out.docx") | |
5. Run the sample using following command | |
python3 SampleWord.py |
Als u al een .NET-, Python 3.9.6- en PIP-omgeving hebt ingesteld, kunt u vanaf stap 4 beginnen om de API te gebruiken. Er wordt voorgesteld om Python 3.9.6 met API te gebruiken in plaats van het oudere Python2.x.
Er wordt ook een werkende basisvoorbeeldcode gegeven die de API gebruikt om de installatie te verifiëren. U kunt andere voorbeelden proberen en de API-functies verkennen om de verschillende voorbeelden te produceren die u met de API wilt produceren.