【Python】デバイスとの通信を可能にする汎用コマンドライン「python-adb」のインストール

スポンサーリンク

「python-adb」のインストールについて解説しています。adb(Android Debug Bridge)は、デバイスとの通信を可能にする汎用コマンドライン ツールです。

「python-adb(https://github.com/google/python-adb)」は、USB 通信に libusb1(単一のアプリケーションで複数のUSBとのやり取りを扱える) を使用する、ADB および Fastboot(PCからFastbootコマンドを使って操作する) プロトコルの純粋な Python 実装が含まれている。

■Python

今回のPythonのバージョンは、「3.8.5」を使用しています。(Windows10)(pythonランチャーでの確認)

■python-adbをインストールする

python-adbをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

pip install adb

起動後、上記のコマンドを入力し、Enterキーを押します。

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、バージョンの切り替えを行います。

py -3.8 -m pip install adb

切り替えるために、上記のコマンドを入力し、Enterキーを押します。

Defaulting to user installation because normal site-packages is not writeable
Collecting adb
  Downloading adb-1.3.0.tar.gz (27 kB)
  Preparing metadata (setup.py) ... done
Collecting libusb1>=1.0.16
  Downloading libusb1-3.0.0-py3-none-win_amd64.whl (140 kB)
     ---------------------------------------- 140.1/140.1 kB 832.7 kB/s eta 0:00:00
Collecting M2Crypto<=0.26.4,>=0.21.1
  Downloading M2Crypto-0.26.4.tar.gz (1.1 MB)
     ---------------------------------------- 1.1/1.1 MB 2.0 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Collecting typing
  Downloading typing-3.7.4.3.tar.gz (78 kB)
     ---------------------------------------- 78.6/78.6 kB 4.3 MB/s eta 0:00:00
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: adb, M2Crypto, typing
  Building wheel for adb (setup.py) ... done
  Created wheel for adb: filename=adb-1.3.0-py3-none-any.whl size=34954 sha256=c96c8626199f6e609eee14caea327f643f71cf7d2d56de5a84e0120b7e12bbb7
  Stored in directory: c:\users\user_\appdata\local\pip\cache\wheels\38\f7\8f\df83128aa1195f4184c7504b3c8d10f2c6fdf4ec3f9a54704e
  Building wheel for M2Crypto (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [57 lines of output]
      running bdist_wheel
      running build
      running build_py
      copying M2Crypto\ASN1.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\AuthCookie.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\BIO.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\BN.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\callback.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\DH.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\DSA.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\EC.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\Engine.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\Err.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\EVP.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\ftpslib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\httpslib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2crypto.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2urllib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2urllib2.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2xmlrpclib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\Rand.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\RC4.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\RSA.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\six.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\SMIME.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\threading.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\util.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\X509.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\__init__.py -> build\lib.win-amd64-3.8\M2Crypto
      creating build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\constants.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\packet.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\PublicKey.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\PublicKeyRing.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\RSA.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\__init__.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      creating build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\cb.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Checker.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Cipher.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Connection.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Context.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Session.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\SSLServer.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\ssl_dispatcher.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\timeout.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\TwistedProtocolWrapper.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\__init__.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      running build_ext
      building 'M2Crypto._m2crypto' extension
      creating build\temp.win-amd64-3.8
      creating build\temp.win-amd64-3.8\Release
      creating build\temp.win-amd64-3.8\Release\SWIG
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" "-IC:\Program Files\OpenSSL\include" -IC:\Users\user_\AppData\Local\Temp\pip-install-efjz2j2w\m2crypto_f80b2a38f58b45bd96e3b7f6fd35d835\SWIG "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" /TcSWIG/_m2crypto_wrap.c /Fobuild\temp.win-amd64-3.8\Release\SWIG/_m2crypto_wrap.obj -Wno-deprecated-declarations -DTHREADING -D_CRT_SECURE_NO_WARNINGS
      cl : コマンド ライン error D8021 : 数値型引数 '/Wno-deprecated-declarations' は無効です。
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for M2Crypto
  Running setup.py clean for M2Crypto
  Building wheel for typing (setup.py) ... done
  Created wheel for typing: filename=typing-3.7.4.3-py3-none-any.whl size=26325 sha256=a193a90a6cc3be903a520f31929ea7d748de85f61d4e1bedef9aa2abf062e743
  Stored in directory: c:\users\user_\appdata\local\pip\cache\wheels\5e\5d\01\3083e091b57809dad979ea543def62d9d878950e3e74f0c930
Successfully built adb typing
Failed to build M2Crypto
Installing collected packages: libusb1, typing, M2Crypto, adb
  Running setup.py install for M2Crypto ... error
  error: subprocess-exited-with-error

  × Running setup.py install for M2Crypto did not run successfully.
  │ exit code: 1
  ╰─> [62 lines of output]
      running install
      C:\Users\user_\AppData\Roaming\Python\Python38\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
        warnings.warn(
      running build
      running build_py
      creating build
      creating build\lib.win-amd64-3.8
      creating build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\ASN1.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\AuthCookie.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\BIO.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\BN.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\callback.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\DH.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\DSA.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\EC.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\Engine.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\Err.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\EVP.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\ftpslib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\httpslib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2crypto.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2urllib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2urllib2.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\m2xmlrpclib.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\Rand.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\RC4.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\RSA.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\six.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\SMIME.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\threading.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\util.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\X509.py -> build\lib.win-amd64-3.8\M2Crypto
      copying M2Crypto\__init__.py -> build\lib.win-amd64-3.8\M2Crypto
      creating build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\constants.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\packet.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\PublicKey.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\PublicKeyRing.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\RSA.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      copying M2Crypto\PGP\__init__.py -> build\lib.win-amd64-3.8\M2Crypto\PGP
      creating build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\cb.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Checker.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Cipher.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Connection.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Context.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\Session.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\SSLServer.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\ssl_dispatcher.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\timeout.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\TwistedProtocolWrapper.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      copying M2Crypto\SSL\__init__.py -> build\lib.win-amd64-3.8\M2Crypto\SSL
      running build_ext
      building 'M2Crypto._m2crypto' extension
      creating build\temp.win-amd64-3.8
      creating build\temp.win-amd64-3.8\Release
      creating build\temp.win-amd64-3.8\Release\SWIG
      C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" "-IC:\Program Files\OpenSSL\include" -IC:\Users\user_\AppData\Local\Temp\pip-install-efjz2j2w\m2crypto_f80b2a38f58b45bd96e3b7f6fd35d835\SWIG "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" /TcSWIG/_m2crypto_wrap.c /Fobuild\temp.win-amd64-3.8\Release\SWIG/_m2crypto_wrap.obj -Wno-deprecated-declarations -D_CRT_SECURE_NO_WARNINGS -DTHREADING
      cl : コマンド ライン error D8021 : 数値型引数 '/Wno-deprecated-declarations' は無効です。
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> M2Crypto

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

[notice] A new release of pip available: 22.2.2 -> 22.3.1
[notice] To update, run: C:\Program Files\Python38\python.exe -m pip install --upgrade pip

Enterキーを押すと、本来であれば、インストールが開始され、「Successfully installed」と表示されますが、Errorが発生しました。Errorの発生原因を調べ、「Visual C++ Build Tools 」などのインストールも行いましたが、Errorが出力され、解決できず。途方に暮れていましたが、「Error while buliding pysha3 with pip? ERROR: Failed building wheel for pysha3」という記事を見つけ、同じようなErrorが発生しているので、この記事内でコメントされている方を参考にして、Pythonのversionを下げてみることにしました。今回は「Python 3.6.8」にインストールしてみます。

C:\Users\user_>py -3.6 -m pip install adb
Defaulting to user installation because normal site-packages is not writeable
Collecting adb
  Using cached adb-1.3.0.tar.gz (27 kB)
  Preparing metadata (setup.py) ... done
Collecting libusb1>=1.0.16
  Using cached libusb1-3.0.0-py3-none-win_amd64.whl (140 kB)
Requirement already satisfied: rsa in c:\users\user_\appdata\roaming\python\python36\site-packages (from adb) (4.7.2)
Requirement already satisfied: pyasn1>=0.1.3 in c:\users\user_\appdata\roaming\python\python36\site-packages (from rsa->adb) (0.4.8)
Building wheels for collected packages: adb
  Building wheel for adb (setup.py) ... done
  Created wheel for adb: filename=adb-1.3.0-py3-none-any.whl size=34933 sha256=cb05527ad046ff8db0732d1ebd2428ca92c893ce8f31881751d7d3e35c5cbdef
  Stored in directory: c:\users\user_\appdata\local\pip\cache\wheels\dd\d0\ad\ee1f9f1b42438c59196f6d5f5b61a0ccba75729043ea124f29
Successfully built adb
Installing collected packages: libusb1, adb
  WARNING: The scripts pyadb.exe and pyfastboot.exe are installed in 'C:\Users\user_\AppData\Roaming\Python\Python36\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed adb-1.3.0 libusb1-3.0.0

インストールしてみると、「WARNING(警告)」は出力されているものの、Errorではなく、「Successfully installed」と表示されていますので、ひとまずインストールが成功となりました。

コメント

タイトルとURLをコピーしました