Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d127ce2

Browse files
Day 28 - Share your Python App via PyInstaller
1 parent 5e328d7 commit d127ce2

File tree

8 files changed

+63
-0
lines changed

8 files changed

+63
-0
lines changed

‎tutorial-reference/Day_28/build.ps1‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.\Scripts\activate
2+
pyinstaller src/wsgi.py -F `
3+
--name "cfe-os-windows" `
4+
--icon='icon.ico' `
5+
--add-data "src\data\*;data" `
6+
--add-data "src\data\*.jpg;data" `
7+
--hidden-import waitress `
8+
--clean

‎tutorial-reference/Day_28/build.sh‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source bin/activate
2+
pyinstaller src/wsgi.py -F \
3+
--name "cfe-os-mac" \
4+
--icon='icon.icns' \
5+
--add-binary='/System/Library/Frameworks/Tk.framework/Tk':'tk' \
6+
--add-binary='/System/Library/Frameworks/Tcl.framework/Tcl':'tcl' \
7+
--add-data "src/data/*:data" \
8+
--add-data "src/data/*.jpg:data" \
9+
--hidden-import waitress \
10+
--clean

‎tutorial-reference/Day_28/pyvenv.cfg‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
home = /usr/local/bin
2+
include-system-site-packages = false
3+
version = 3.6.8
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .main import *
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pathlib
2+
from flask import Flask
3+
4+
from .resources import get_resource_path
5+
BASE_DIR = pathlib.Path(__file__).resolve().parent
6+
DATA_DIR = get_resource_path("data")
7+
IMG_PATH = DATA_DIR / 'beach.jpg'
8+
web_app = Flask(__name__)
9+
10+
@web_app.route("/", methods=['GET']) #http://localhost:5000/
11+
def index():
12+
return {"dir": str(BASE_DIR),
13+
'data_dir': str(DATA_DIR),
14+
'IMG_PATH': IMG_PATH.exists()
15+
}, 200
16+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pathlib
2+
import sys
3+
4+
5+
def get_resource_path(relative_path):
6+
"""
7+
relative_path = "data/beach.jpg"
8+
relative_path = pathlib.Path("data") / "beach.jpg"
9+
relative_path = os.path.join("data", "beach.jpg")
10+
"""
11+
rel_path = pathlib.Path(relative_path)
12+
dev_base_path = pathlib.Path(__file__).resolve().parent.parent
13+
base_path = getattr(sys, "_MEIPASS", dev_base_path)
14+
return base_path / rel_path
87.2 KB
Loading[フレーム]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from cfe_os import web_app
2+
from waitress import serve
3+
4+
5+
if __name__ == "__main__":
6+
serve(
7+
web_app,
8+
host='127.0.0.1',
9+
port=5002,
10+
threads=2
11+
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /