Installation

Cài đặt Aspose.BarCode FOSS cho Python

Aspose.BarCode FOSS for Python is distributed as a pure-Python package on PyPI. There are no native extensions to compile, no system libraries to install, and no third-party runtime required.


Prerequisites

RequirementDetail
Phiên bản Python3.12 or later
Quản lý góiPip (được kết hợp với CPython)
Hệ điều hànhWindows, macOS, Linux (mọi nền tảng chạy CPython)
Công cụ / Build ToolsKhông cần thiết
Hệ thống góiKhông cần thiết

1. Install via pip

Cách đơn giản nhất để cài đặt Aspose.BarCode FOSS là trực tiếp từ PyPI:

pip install aspose-barcode-foss

pip sẽ tải xuống và cài đặt gói. không cần thiết cấu hình sau cấy ghép.

Để cài đặt một phiên bản cố định cho các bản dựng có thể tái tạo:

pip install aspose-barcode-foss==0.1.0

2. Set Up a Virtual Environment

Sử dụng một môi trường ảo giữ cho thư viện tách biệt khỏi các dự án Python khác.

Tạo và kích hoạt môi trường ảo:

# Create the environment
python -m venv .venv

# Activate on Linux / macOS
source .venv/bin/activate

# Activate on Windows (Command Prompt)
.venv\Scripts\activate.bat

# Activate on Windows (PowerShell)
.venv\Scripts\Activate.ps1

Cài đặt thư viện trong môi trường đã kích hoạt:

pip install aspose-barcode-foss

Ghi lại các phụ thuộc để tái tạo:

pip freeze > requirements.txt

3. Verify the Installation

Sau khi cài đặt, xác minh rằng thư viện được nhập khẩu đúng cách:

import aspose_barcode_foss as barcode

bc = barcode.code128("TEST")
print(f"Generated barcode with {bc.symbol.matrix.width}x{bc.symbol.matrix.height} modules")

Bạn cũng có thể kiểm tra phiên bản đã cài đặt bằng pip:

pip show aspose-barcode-foss

Nó in phiên bản, tác giả và giấy phép (MIT).


Khởi động nhanh: tạo một mã thanh

Các kịch bản sau tạo ra mã thanh Code 128 và lưu nó như SVG:

import aspose_barcode_foss as barcode
from aspose_barcode_foss import RenderOptions

bc = barcode.code128("Hello World")
svg = bc.to_svg(options=RenderOptions(show_text=True))

with open("barcode.svg", "w") as f:
    f.write(svg)
print("Saved barcode.svg")

Tạo một mã QR và lưu nó như PNG:

import aspose_barcode_foss as barcode
from aspose_barcode_foss import QrOptions, QrErrorCorrectionLevel

bc = barcode.qr(
    "https://example.com",
    encode=QrOptions(error_correction_level=QrErrorCorrectionLevel.H),
)

with open("qr.png", "wb") as f:
    f.write(bc.to_png())
print("Saved qr.png")

Ghi chú về nền tảng

Windows, macOS và Linux: Thư viện là giống nhau trên tất cả các nền tảng. không có đường mã cụ thể cho nền kinh doanh hoặc mở rộng nhị phân.

Docker / Server không có: Bởi vì không có phụ thuộc hệ thống-chung, thư viện hoạt động bên trong hình ảnh Docker mỏng (như: python:3.12-slimKhông cài đặt thêm gói.

CI/CD: thêm pip install aspose-barcode-foss đến bước phụ thuộc của ống CI của bạn. Không cần thiết lập thêm.


Bước tiếp theo

  • Quickstart: Đầu tiên làm việc mã thanh với mã hóa và render tùy chọn
  • License:• Chi tiết giấy phép MIT
  • Hướng dẫn Developer: Per-symbology mã hóa tùy chọn, kiểm soát rendering và ví dụ code

See Also

 Tiếng Việt