diff --git a/docs/how-to-run-in-15-minutes.zh.md b/docs/how-to-run-in-15-minutes.zh.md index 8e5ec21..906c72e 100644 --- a/docs/how-to-run-in-15-minutes.zh.md +++ b/docs/how-to-run-in-15-minutes.zh.md @@ -30,15 +30,26 @@ $ conda activate py38 ```bash $ python3 -m pip install pyflow-0.1.0-py38-none-linux_x86_64.whl --force-reinstall ``` -完成后应该可以 `import pyflow` + +.whl 封装了 `pyflow`和 Rust 可执行文件 `run_with_plugins_python_wrap`。完成后应该可以运行 ```bash +$ run_with_plugins_python_wrap --help +run_with_plugins 1.0 +megvii +... $ python3 Python 3.8.3 (default, May 19 2020, 18:47:26) [GCC 7.3.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pyflow ``` -.whl 打包了可执行文件 `run_with_plugins`,如果使用 conda 位置应该在 + +此处常见问题:`error while loading shared libraries: libpython3.8.xxx`。如果使用 conda 只需要 +```bash +$ export LD_LIBRARY_PATH=/home/`whoami`/miniconda3/pkgs/python-3.8.11-h12debd9_0_cpython/lib:${LD_LIBRARY_PATH} +``` + +被封装的内容安装在 miniconda3 路径下,有兴趣不妨确认一下 ```bash $ cd ${HOME}/miniconda3/envs/py38/lib/python3.8/site-packages/pyflow/ $ sudo apt install build-essential -y @@ -51,18 +62,12 @@ megvii ## Python“开机自检” +`logical_test` 是 MegFlow/flow-python/examples 下最基础的计算图测试用例,运行能正常结束表示 MegFlow 编译成功、基本语义无问题。 ```bash -$ cd ${MegFlow_PATH}/flow-python/examples # 这行必须 -$ run_with_plugins -p logical_test -``` - -`logical_test` 是 examples 下最基础的计算图测试用例,运行能正常结束表示 MegFlow 编译成功、基本语义无问题。 - -此处常见问题:`error while loading shared libraries: libpython3.8.xxx`。如果使用 conda 只需要 -```bash -$ export LD_LIBRARY_PATH=/home/`whoami`/miniconda3/pkgs/python-3.8.11-h12debd9_0_cpython/lib:${LD_LIBRARY_PATH} +$ cd ${MegFlow_PATH}/flow-python/examples +$ run_with_plugins_python_wrap -p logical_test +... ``` - > 工作原理:[pyflow](../flow-python/pyflow/__init__.py) 仅是一层接口,由 run_with_plugins “注入”建图/调度/优化等实现。 ## Python Built-in Applications diff --git a/flow-python/examples/cat_finder/README.md b/flow-python/examples/cat_finder/README.md index df5e4d5..2ad1c16 100644 --- a/flow-python/examples/cat_finder/README.md +++ b/flow-python/examples/cat_finder/README.md @@ -53,6 +53,7 @@ $ python3 ```bash $ cd flow-python/examples $ pip3 install -r requires.txt +$ run_with_plugins_python_wrap -c cat_finder/image_cpu.toml -p cat_finder # 如果用 prebuilt 包,不需要用`cargo run --example run_with_plugins --` $ cargo run --example run_with_plugins -- -c cat_finder/image_gpu.toml -p cat_finder # 有 GPU 的机器执行这个 $ cargo run --example run_with_plugins -- -c cat_finder/image_cpu.toml -p cat_finder # 无 GPU 的 laptop 执行这句 ``` @@ -110,6 +111,7 @@ $ ffmpeg -re -stream_loop -1 -i ${models}/cat_finder_testdata/test1.ts -c copy - 启动视频识别服务 ```bash $ cd flow-python/examples +$ run_with_plugins_python_wrap -c cat_finder/video_cpu.toml -p cat_finder # 如果用 prebuilt 包,不需要用`cargo run --example run_with_plugins --`编译 $ cargo run --example run_with_plugins -- -c cat_finder/video_gpu.toml -p cat_finder # 有 GPU 的机器 $ cargo run --example run_with_plugins -- -c cat_finder/video_cpu.toml -p cat_finder # 无 GPU 的设备用这句 ``` diff --git a/flow-python/examples/electric_bicycle/README.md b/flow-python/examples/electric_bicycle/README.md index 3054c9c..4959460 100644 --- a/flow-python/examples/electric_bicycle/README.md +++ b/flow-python/examples/electric_bicycle/README.md @@ -38,7 +38,8 @@ $ pip3 install onnxruntime --user 启动服务 ```bash $ cd flow-python/examples -$ cargo run --example run_with_plugins -- -c electric_bicycle/electric_bicycle.toml -p electric_bicycle +$ run_with_plugins_python_wrap -c electric_bicycle/electric_bicycle.toml -p electric_bicycle # prebuilt 安装用这个,不需要`cargo run`来编译 +$ cargo run --example run_with_plugins -- -c electric_bicycle/electric_bicycle.toml -p electric_bicycle # 源码或 docker 安装用这个 ``` 服务配置文件在`electric_bicycle/electric_bicycle.toml`,解释参考 [how-to-add-graph](../.../../docs/how-to-add-graph.zh.md) 。这里只需要打开 8083 端口服务,操作和[猫猫围栏](../cat_finder/README.zh.md) 近似。 diff --git a/flow-python/gen_whl.sh b/flow-python/gen_whl.sh index 9f55e8d..151bcef 100755 --- a/flow-python/gen_whl.sh +++ b/flow-python/gen_whl.sh @@ -8,15 +8,15 @@ python3 whl-py36-setup.py bdist_wheel -p linux-x86_64 -d py36_dist --python-ta conda activate py37 cargo build --example run_with_plugins --release -ldd pyflow/run_with_plugins cp ../target/release/examples/run_with_plugins ./pyflow/ +ldd pyflow/run_with_plugins rm -rf ./build python3 whl-py37-setup.py bdist_wheel -p linux-x86_64 -d py37_dist --python-tag py37 conda activate py38 cargo build --example run_with_plugins --release -ldd pyflow/run_with_plugins cp ../target/release/examples/run_with_plugins ./pyflow/ +ldd pyflow/run_with_plugins rm -rf ./build python3 whl-py38-setup.py bdist_wheel -p linux-x86_64 -d py38_dist --python-tag py38 diff --git a/flow-python/pyflow/command_line.py b/flow-python/pyflow/command_line.py new file mode 100644 index 0000000..469397d --- /dev/null +++ b/flow-python/pyflow/command_line.py @@ -0,0 +1,19 @@ +import os +import sys +import subprocess +import pkg_resources +def main(): + bin_exist = pkg_resources.resource_exists('pyflow', 'run_with_plugins') + if not bin_exist: + print('cannot find run_with_plugins, exit!') + sys.exit(-1) + bin_path = pkg_resources.resource_filename('pyflow', 'run_with_plugins') + + sys.argv[0] = bin_path + ret = subprocess.Popen(sys.argv) + ret.wait() + +if __name__ == '__main__': + main() + + diff --git a/flow-python/whl-py36-setup.py b/flow-python/whl-py36-setup.py index 10536c7..4ce3f64 100644 --- a/flow-python/whl-py36-setup.py +++ b/flow-python/whl-py36-setup.py @@ -39,6 +39,10 @@ python_requires='>=3.6,<3.7', package_data={ "":['run_with_plugins'] - } + }, + entry_points={ + 'console_scripts':['run_with_plugins_python_wrap=pyflow.command_line:main'], + }, + ) diff --git a/flow-python/whl-py37-setup.py b/flow-python/whl-py37-setup.py index cb8eb63..48f8d98 100644 --- a/flow-python/whl-py37-setup.py +++ b/flow-python/whl-py37-setup.py @@ -39,6 +39,10 @@ python_requires='>=3.7,<3.8', package_data={ "":['run_with_plugins'] - } + }, + entry_points={ + 'console_scripts':['run_with_plugins_python_wrap=pyflow.command_line:main'], + }, + ) diff --git a/flow-python/whl-py38-setup.py b/flow-python/whl-py38-setup.py index 8f90cb0..6b35525 100644 --- a/flow-python/whl-py38-setup.py +++ b/flow-python/whl-py38-setup.py @@ -39,6 +39,10 @@ python_requires='>=3.8,<3.9', package_data={ "":['run_with_plugins'] - } + }, + entry_points={ + 'console_scripts':['run_with_plugins_python_wrap=pyflow.command_line:main'], + }, + )