本教程提供了有关如何安装 python 以通过 java 运行 Aspose.Barcode for python 的详细步骤。它假定您已在系统上安装了 Docker,并指导您安装在 Python 中运行 Aspose.Barcode 代码所需的所有必要软件。您将在这些步骤中安装 Python 并创建一个新的 Barcode 映像以验证已建立的环境。
安装 Python 以通过 Java 运行 Aspose.Barcode for Python 的步骤
- 使用 docker 命令拉取最新的 Ubuntu 镜像
- 使用 docker 命令运行 Ubuntu 映像
- 安装须藤命令
- 安装 Java
- 安装 Python
- 安装 Pip 命令
- 安装 Aspose.Barcode for Python via Java 和 JPype1
- 使用 Pip 安装 Pillow 映像库
- 编写并运行 Aspose.BarCode for Python 代码以创建条码
请注意,这些步骤假设您使用 Docker 来测试完整的环境,但是如果您不想使用 Docker,您可以忽略最初的前两个步骤并在终端或 Linux 中的命令提示符中执行其余命令, Windows 或 Mac 环境。您需要安装 Python 和 Pip3 来安装 Aspose.Barcode、JPype1 和 Pillow 库,以运行以下脚本末尾给出的示例代码。
安装 Python 以通过 Java 运行 Aspose.Barcode for Python 的脚本
1. Load the latest Ubuntu Image | |
docker pull ubuntu | |
2. Run Ubuntu Image Using Docker Command | |
docker run -it ubuntu | |
3. Install Sudo Command | |
apt update | |
apt upgrade | |
apt install sudo | |
sudo apt update | |
4. Install Java Runtime environment | |
sudo apt install default-jre | |
5. Install Python3 | |
sudo apt update | |
sudo apt upgrade | |
sudo apt install -y python3 | |
6. Installing Pip Command | |
sudo apt update | |
sudo apt install python3-pip | |
7. Install Aspose.Barcode | |
pip install aspose-barcode-for-python-via-java | |
pip install JPype1 | |
8. Install Pillow imaging library | |
pip install Pillow | |
9. Write Sample Program and save It As SampleBarcode.Py And Run Program | |
python3 SampleBarcode.py | |
SAMPLE CODE TO BE WRITTEN IN SampleBacrode.Py | |
from asposebarcode import Generation | |
# Create an object of BarCodeGenerator class | |
# Specify Barcode Encode Type as QR | |
encode_type = Generation.EncodeTypes.QR | |
GenerateQRCode = Generation.BarcodeGenerator(encode_type, None) | |
# Set QR code text to be encoded as generated QR code | |
GenerateQRCode.setCodeText("Python Test QR") | |
#BarCodeImageFormat.PNG.value | |
file_path = "QR_Code.png" | |
imageFormat= Generation.BarCodeImageFormat(3) | |
# Saving the QR code in PNG image format | |
GenerateQRCode.save(file_path, imageFormat) | |
10. Run the sample using following command | |
python3 SampleBarcode.py |
如果您已经设置了 Sudo、Java 和 Python3 环境,则可以从第 6 步开始使用 API。建议使用带有 API 的 Python3 而不是旧的 Python2.x。
还提供了一个使用 API 的工作基本示例代码来验证安装。您可以在您的 docker 容器中提交更改,并且只需要为您想要使用 API 生成的不同示例执行第 9 步。