このチュートリアルでは、PythonをインストールしてJava経由でPython用のAspose.Barcodeを実行する方法の詳細な手順を説明します。システムにDockerがインストールされていることを前提とし、PythonでAspose.Barcodeコードを実行するために必要なすべてのソフトウェアをインストールするようにガイドします。これらの手順でPythonをインストールし、新しいBarcodeイメージを作成して、確立された環境を確認します。
PythonをインストールしてJava経由でPython用のAspose.Barcodeを実行する手順
- dockerコマンドを使用して、Ubuntuの最新のイメージをプルします
- dockerコマンドを使用してUbuntuイメージを実行します
- Sudoコマンドをインストールする
- Javaをインストールする
- Pythonをインストールする
- Pipコマンドのインストール
- Aspose.Barcode for Python via JavaとJPype1をインストールします
- Pipを使用してPillowイメージングライブラリをインストールします
- Aspose.BarCode for Pythonコードを記述して実行し、バーコードを作成します
これらの手順は、Dockerを使用して完全な環境をテストしていることを前提としていますが、Dockerを使用したくない場合は、最初の2つの手順を無視して、ターミナルの残りのコマンドまたはLinuxのコマンドプロンプトを実行できます。 WindowsまたはMac環境。次のスクリプトの最後にあるサンプルコードを実行するには、Aspose.Barcode、JPype1、およびPillowライブラリをインストールするにはPythonとPip3をインストールする必要があります。
PythonをインストールしてJava経由でPython用のAspose.Barcodeを実行するスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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を使用できます。古いPython2.xではなく、APIでPython3を使用することをお勧めします。
インストールを確認するために、APIを使用した実用的な基本サンプルコードも提供されています。 Dockerコンテナーで変更をコミットでき、APIを使用して作成する別の例に対してステップ9を実行するだけで済みます。