安裝
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
無論是從 PyPI 安裝程式庫,還是從 GitHub 複製程式庫,我們都建議您使用有效的虛擬環境執行下列步驟。如要瞭解如何建立及啟用虛擬環境,請參閱「虛擬環境」說明文件。
從 PyPI 安裝模組
這個程式庫會發布在 PyPI 上,您可以使用 pip 透過下列指令安裝:
python -m pip install google-ads
從 GitHub 安裝程式庫
您可以從 GitHub 將程式庫的原始碼複製到本機電腦。複製原始碼有助於輕鬆執行範例,或開發程式庫本身。請注意,如要設定程式庫以供使用,必須先執行其中一個驗證範例。
確認環境中是否已安裝 python3.8
以上版本。
最簡單的方式是使用 pyenv
:
pyenv local 3.8
從 GitHub 複製用戶端程式庫:
git clone git@github.com:googleads/google-ads-python.git
輸入存放區並安裝:
cd google-ads-python
python -m pip install .
如果您打算開發程式庫,請在進行任何變更前後執行單元測試:
請確認環境中已安裝所有支援的 Python 語言版本。使用 pyenv
:
pyenv local 3.8 3.9 3.10 3.11 3.12
安裝程式庫的測試專屬依附元件:
python -m pip install .[tests]
執行單元測試,確保程式庫運作正常:
nox
選用:您也可以使用 Docker 執行單元測試。首先,您必須安裝 Docker。然後,從 google-ads-python
目錄執行下列指令:
docker build -t google-ads-python:test .
docker run -it google-ads-python:test nox
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-27 (世界標準時間)。
[null,null,["上次更新時間:2025-08-27 (世界標準時間)。"],[[["\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"]]