LoginSignup
1
4

More than 3 years have passed since last update.

Python exeファイル作成(画像ダウンロード処理)

Posted at

Pythonでexeファイルを作成してみた。
※前提条件、pipコマンドが実行できる状態(私はAnaconda3をインストールしていました)

①Pythonファイルをexe)ファイルに変換してくれるライブラリをインストール

コマンドプロンプトより
pip install pyinstaller

②Pythonファイルを作成(画像をDLしてローカルに保存)UTF-8

hello.py
import requests
from datetime import datetime
try:
    url = input("DLするURLを入力してください ※未入力時はhttps://bookandengineer.com/wp-content/uploads/2019/02/キャプチャ.jpg")

    if url=='':
        url='https://bookandengineer.com/wp-content/uploads/2019/02/キャプチャ.jpg'

    file_name = f'./img/test.jpg'

    response = requests.get(url)
    image = response.content

    with open(file_name, "wb") as aaa:
        aaa.write(image)

    print(f'画像DL成功(取得URL[{url}] / 画像パス[{file_name}])')

except Exception as e:
    print(f'画像DL失敗(取得URL[{url}] / 画像パス[{file_name}])')
    print(e)

input("何か入力すると処理を終了します")

③exe作成(hello.pyを配置しているディレクトリに移動してから)

コマンドプロンプトより
pyinstaller hello.py --onefile

④作成されたexeを実行

1.JPG
2.JPG
3.JPG
4.JPG

1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4