Cài đặt
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Cho dù bạn đang cài đặt thư viện từ PyPI hay sao chép thư viện đó từ GitHub, bạn nên thực hiện các bước dưới đây bằng một môi trường ảo đang hoạt động. Để biết thông tin về cách tạo và kích hoạt môi trường ảo, hãy xem tài liệu Môi trường ảo.
Cài đặt mô-đun từ PyPI
Thư viện này được phân phối trên PyPI và có thể được cài đặt bằng pip bằng lệnh sau:
python -m pip install google-ads
Cài đặt thư viện từ GitHub
Bạn có thể sao chép mã nguồn cho thư viện từ GitHub vào thiết bị của mình. Bạn nên sao chép mã nguồn để dễ dàng thực thi các ví dụ hoặc phát triển chính thư viện. Để tham khảo, việc chạy một trong các ví dụ về quy trình xác thực là bước bắt buộc trong việc định cấu hình thư viện để sử dụng.
Đảm bảo rằng python3.8
trở lên có trong môi trường của bạn.
Cách đơn giản nhất là sử dụng pyenv
:
pyenv local 3.8
Sao chép thư viện ứng dụng trên GitHub:
git clone git@github.com:googleads/google-ads-python.git
Nhập kho lưu trữ rồi cài đặt:
cd google-ads-python
python -m pip install .
Nếu bạn dự định phát triển thư viện, hãy chạy các kiểm thử đơn vị trước và sau khi thực hiện bất kỳ thay đổi nào:
Đảm bảo bạn có tất cả các phiên bản được hỗ trợ của ngôn ngữ Python trong môi trường của mình. Sử dụng pyenv
::
pyenv local 3.8 3.9 3.10 3.11 3.12
Cài đặt các phần phụ thuộc dành riêng cho kiểm thử của thư viện:
python -m pip install .[tests]
Chạy các bài kiểm thử đơn vị để đảm bảo thư viện hoạt động đúng cách:
nox
Không bắt buộc: bạn cũng có thể chạy kiểm thử đơn vị bằng Docker. Trước tiên, bạn phải cài đặt Docker. Sau đó, từ thư mục google-ads-python
, hãy chạy lệnh sau:
docker build -t google-ads-python:test .
docker run -it google-ads-python:test nox
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-27 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-27 UTC."],[[["\u003cp\u003eThe Google Ads Python library can be installed from PyPI using pip with the command \u003ccode\u003epython -m pip install google-ads\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo install from GitHub, clone the repository, navigate into it, and run \u003ccode\u003epython -m pip install .\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEnsure you have Python 3.8 or later installed in your environment, potentially using pyenv.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers should run unit tests before and after making changes, utilizing nox or Docker for execution.\u003c/p\u003e\n"],["\u003cp\u003eFor library setup and usage, refer to the Virtual Environment and authentication example documentation.\u003c/p\u003e\n"]]],[],null,["# Installation\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nWhether you're installing the library from PyPI or cloning it from GitHub, we\nrecommended that you conduct the below steps using an active virtual\nenvironment. For information on how to create and activate a virtual\nenvironment, see the [Virtual Environment](//docs.python.org/3/tutorial/venv.html) documentation.\n\nInstall the module from PyPI\n----------------------------\n\nThe library is distributed on [PyPI](//pypi.org/project/google-ads/) and can\nbe installed using [pip](//pip.pypa.io/en/stable/installing) with the\nfollowing command: \n\n python -m pip install google-ads\n\nInstall the library from GitHub\n-------------------------------\n\nThe source code for the library can be cloned from [GitHub](https://github.com/googleads/google-ads-python/)\nonto your local machine. It's useful to clone the source code in order to easily\nexecute the examples or to develop the library itself. For reference, running\none of the authentication examples is a required step in configuring the library\nfor use.\n\n1. Ensure that `python3.8` or later is present in your environment.\n The simplest way is to use [`pyenv`](//github.com/pyenv/pyenv-installer):\n\n pyenv local 3.8\n\n2. Clone the client library from GitHub:\n\n git clone git@github.com:googleads/google-ads-python.git\n\n3. Enter the repository and install it:\n\n cd google-ads-python\n python -m pip install .\n\n4. If you intend to develop the library, run the unit tests before and after\n making any changes:\n\n 1. Ensure you have all supported versions of the Python language available in\n your environment. Using `pyenv`::\n\n pyenv local 3.8 3.9 3.10 3.11 3.12\n\n 2. Install the test-specific dependencies of the library:\n\n python -m pip install .[tests]\n\n 3. Run the unit tests to ensure the library is functioning properly:\n\n nox\n\n 4. Optional: the unit tests can also be run using Docker. First, you must\n have [Docker installed](https://docs.docker.com/get-docker/). Then, from\n the `google-ads-python` directory, run the following:\n\n docker build -t google-ads-python:test .\n docker run -it google-ads-python:test nox"]]