I have a Python file called recognize.py, which takes multiple images and performs OCR with multiple processes, where ocr_tools
is a large self-written module:
import argparse
import json
from multiprocessing import Pool
from ocr_tools import Organize
organizer = Organize()
parser = argparse.ArgumentParser(description="Recognize the contents on a lab report and return a json string.")
parser.add_argument("-i", "--image", nargs="*", required=True, help="path to input image file")
args = parser.parse_args()
if __name__ == "__main__":
with Pool() as p:
report_set = json.dumps({"report_set": p.map(organizer.finalize_report, args.image)}, ensure_ascii=False)
print(report_set)
For ocr_tools
, I also have a requirements.txt generated by pipreqs for users to install the required packages from PyPI:
numpy==1.14.3
regex==2018.2.21
requests==2.18.4
pandas==0.23.0
opencv_python==3.4.1.15
scikit_learn==0.19.1
If I distribute these files and modules, users should be able to execute python recognize.py --image <path_to_an_image>
from the command lines and get OCR results after they install those packages listed in requirements.txt.
Now I wonder if there's a way to further enable users to do something like ocr --image <path_to_an_image>
, i.e. the same job without specifying python
interpreter in the command lines.
I've read a tutorial, How Do I Make My Own Command-Line Commands Using Python? but it seems effective only locally and cannot be distributed. I've also glanced Writing the Setup Script, hoping to find solutions for distribution. However, I don't find a way to specify external packages to be installed from PyPI. (Or maybe I missed something - I am a beginner in Python.) Besides, setup.py seems like neither a good way to install the packages according to comments under the accepted answer of What is setup.py?, nor being capable of enabling CLI.