Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy python script?

This might sound like a very open ended question, but I am a python enthusiast, and pretty new to this world of development. I have developed a python script which takes in an input and gives an output based on the algorithm I have put in place in the script. I want to use this script and package it in a way that it can be used by end users having no technical mindset and are only concerned with input they give and the output they get.

I have used Jupyter Notebook to develop this complex code and I want to know a way about how I can package or deploy this code so that the end user can use it without seeing how it works as it might be overwhelming for them.

Can anyone help me with the idea on how to do it? Something which is Opensource would be preferred.

Thanks

like image 799
Kshitij Yadav Avatar asked Sep 05 '18 14:09

Kshitij Yadav


People also ask

How do you distribute a Python script?

Use PyInstaller, py2exe, Nuitka, or another bundling solution. The most convenient way to deliver a Python application to a user is to provide them with an executable—either a single file or a directory with an easily identified executable somewhere in it.

How do you deploy code written in Python for the client use?

To deploy, you need to upload this artifact to your production machine. To install it, just run dpkg -i my-package. deb . Your virtualenv will be placed at /usr/share/python/ and any script files defined in your setup.py will be available in the accompanying bin directory.


1 Answers

I want to round up this question by suggesting a couple of ways to deploy Python Script or Models:

  • Docker: This is one of the most popular ways of hosting scripts and deploying Machine Learning Models online. You can use Docker to containerize the code and host it as a microservice using different apps.
  • PEX: PEX is a clever tool being developed at Twitter that allows Python code to be shipped as executable zip files.
  • AWS: Using AWS, you can create a free account and get started with hosting/deployment. A lot of resources are available online.
  • PYSimple, Pyinstaller, and Sparrow: As mentioned in the answers above, we can use these packages also to do the task. Please read above.
  • Flask App: If you don't want to use Docker, using a simple flask app, you will be able to host your script online. But there will be a lot of issues as it is not containerized. Best to use Docker.
  • py2exe: If you are looking to convert the Python file into windows executable, Click here
  • cx_Freeze: Similar to the py2exe, you can use this also

I will keep adding more content as I find them, but I think the best way to do it using Docker. Hope this helps.

like image 97
Kshitij Yadav Avatar answered Sep 29 '22 01:09

Kshitij Yadav