webmaster-kazu.com

テクノロジー・データ分析・実践ログ・その他

PythonでDeepL翻訳を使用しテキスト翻訳するための「deepl-translate」をインストールする

カテゴリ: Python【初歩から現場実務的なもの】

Pythonで、最先端のニューラルネットワーク技術を駆使して開発された超高性能な機械翻訳システムである「DeepL翻訳」を使用しテキスト翻訳するための「deepl-translate」のインストールについて解説しています。(Windows10)

今回使用するパッケージ「deepl-translate」は、Pythonの公式パッケージではなく、非公式パッケージとなります。Github:https://github.com/ptrstn/deepl-translate

■環境

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

git version 2.29.2.windows.1

■deepl-translateをインストールする

deepl-translateをインストールを行いますが、今回はWindows10にインストールしたgitを用いてインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

git clone https://github.com/ptrstn/deepl-translate

起動後、上記のコマンドを入力し、Enterキーを押します。リポジトリのクローンを作成します。

cd deepl-translate

クローンを作成後、上記のコマンドを入力し、Enterキーを押します。「deepl-translate」のディレクトリ内に移動します。

python setup.py install --user

移動後、上記のコマンドを入力し、Enterキーを押します。今回はpythonランチャーを使用しており「py -3.8 setup.py install --user」と入力しています。なお、「--user」を付けないとエラーが発生する場合があります。

C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2544.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py:274: UserWarning: Unknown distribution option: 'desription'

warnings.warn(msg)

running install

running bdist_egg

running egg_info

creating deepl_translate.egg-info

writing deepl_translate.egg-info\PKG-INFO

writing dependency_links to deepl_translate.egg-info\dependency_links.txt

writing entry points to deepl_translate.egg-info\entry_points.txt

writing requirements to deepl_translate.egg-info\requires.txt

writing top-level names to deepl_translate.egg-info\top_level.txt

writing manifest file 'deepl_translate.egg-info\SOURCES.txt'

adding license file 'LICENSE' (matched pattern 'LICEN[CS]E*')

reading manifest file 'deepl_translate.egg-info\SOURCES.txt'

writing manifest file 'deepl_translate.egg-info\SOURCES.txt'

installing library code to build\bdist.win-amd64\egg

running install_lib

running build_py

creating build

creating build\lib

creating build\lib\deepl

copying deepl\api.py -> build\lib\deepl

copying deepl\extractors.py -> build\lib\deepl

copying deepl\generators.py -> build\lib\deepl

copying deepl\hacks.py -> build\lib\deepl

copying deepl\settings.py -> build\lib\deepl

copying deepl\utils.py -> build\lib\deepl

copying deepl\__init__.py -> build\lib\deepl

copying deepl\__main__.py -> build\lib\deepl

creating build\bdist.win-amd64

creating build\bdist.win-amd64\egg

creating build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\api.py -> build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\extractors.py -> build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\generators.py -> build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\hacks.py -> build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\settings.py -> build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\utils.py -> build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\__init__.py -> build\bdist.win-amd64\egg\deepl

copying build\lib\deepl\__main__.py -> build\bdist.win-amd64\egg\deepl

byte-compiling build\bdist.win-amd64\egg\deepl\api.py to api.cpython-38.pyc

byte-compiling build\bdist.win-amd64\egg\deepl\extractors.py to extractors.cpython-38.pyc

byte-compiling build\bdist.win-amd64\egg\deepl\generators.py to generators.cpython-38.pyc

byte-compiling build\bdist.win-amd64\egg\deepl\hacks.py to hacks.cpython-38.pyc

byte-compiling build\bdist.win-amd64\egg\deepl\settings.py to settings.cpython-38.pyc

byte-compiling build\bdist.win-amd64\egg\deepl\utils.py to utils.cpython-38.pyc

byte-compiling build\bdist.win-amd64\egg\deepl\__init__.py to __init__.cpython-38.pyc

byte-compiling build\bdist.win-amd64\egg\deepl\__main__.py to __main__.cpython-38.pyc

creating build\bdist.win-amd64\egg\EGG-INFO

copying deepl_translate.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO

copying deepl_translate.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO

copying deepl_translate.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO

copying deepl_translate.egg-info\entry_points.txt -> build\bdist.win-amd64\egg\EGG-INFO

copying deepl_translate.egg-info\requires.txt -> build\bdist.win-amd64\egg\EGG-INFO

copying deepl_translate.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO

zip_safe flag not set; analyzing archive contents...

creating dist

creating 'dist\deepl_translate-1.0.0-py3.8.egg' and adding 'build\bdist.win-amd64\egg' to it

removing 'build\bdist.win-amd64\egg' (and everything under it)

Processing deepl_translate-1.0.0-py3.8.egg

Copying deepl_translate-1.0.0-py3.8.egg to c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages

Adding deepl-translate 1.0.0 to easy-install.pth file

Installing deepl-script.py script to C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts

Installing deepl.exe script to C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts

Installed c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages\deepl_translate-1.0.0-py3.8.egg

Processing dependencies for deepl-translate==1.0.0

Searching for requests==2.23.0

Best match: requests 2.23.0

Adding requests 2.23.0 to easy-install.pth file

Using c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages

Searching for urllib3==1.25.10

Best match: urllib3 1.25.10

Adding urllib3 1.25.10 to easy-install.pth file

Using c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages

Searching for idna==2.9

Best match: idna 2.9

Adding idna 2.9 to easy-install.pth file

Using c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages

Searching for certifi==2020.4.5.1

Best match: certifi 2020.4.5.1

Adding certifi 2020.4.5.1 to easy-install.pth file

Using c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages

Searching for chardet==3.0.4

Best match: chardet 3.0.4

Adding chardet 3.0.4 to easy-install.pth file

Installing chardetect-script.py script to C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts

Installing chardetect.exe script to C:\Users\user\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts

Using c:\users\user\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages

Finished processing dependencies for deepl-translate==1.0.

Enterキーを押すと、上記のメッセージが表示されます。しばらくすると「Finished processing dependencies for deepl-translate==1.0.」と表示されます。これが表示されれば、deepl-translateがインストールされたことになります。

なお、インストールの途中で「UnicodeDecodeError: 'cp932' codec can't decode byte 0xef in position 60」といったエラーが発生する場合は、下記の手順を行うとインストールできます。

Windowsのコントロールパネルの「時計と地域」の「地域」をクリックします。

クリックすると、「地域」のウインドウが表示され、「システムロケールの変更」というボタンがありますので、こちらをクリックします。

クリックすると、「地域の設定」のウインドウが表示されますので、「ベータ:ワールドワイド言語サポートでUnicode UTF-8を使用」のチェックボックスにチェックを入れます。チェックを入れるとWindowsの再起動が必要になりますので、再起動を行います。その後、セットアップを行います。

なお、ワールドワイド言語サポートでUnicode UTF-8を使用したことにより、Windows10内の他のソフトウェアなどに不具合が生じる恐れがありますので、セットアップ後は「ベータ:ワールドワイド言語サポートでUnicode UTF-8を使用」のチェックを外すことを推奨いたします。

セットアップ後に「ベータ:ワールドワイド言語サポートでUnicode UTF-8を使用」のチェックを外しても、deepl-translateを使用することができます。

■インストールの確認

C:\Users\user\deepl-translate>py -3.8 deepl --help

インストールを確認する際は、上記のコマンドを入力し、Enterキーを押します。

Enterキーを押すと、上記のようにヘルプが表示されます。これが表示されればインストールは完了となります。