0

I have written a Python script that I need to share with folks who may or may not have Python installed on their machine. As a dirty hack I figured I could copy my local Python3.6 install into the same folder as the script I made, and then create a .bat file that runs python from the copied Python source ie.

Python36\python.exe script.py %*

In this way I could just send them the folder, and all they have to do is double click the .bat file. Now this does work, but it takes about 2 - 5 mins for script.py to begin executing. How could I configure the copied python source so that it runs like it "should"?

O.D.P
  • 135
  • 1
  • 2
  • 10
  • 1
    There used to be a project that built a Python for 32-bit Windows XP (which also runs on 64-bit Windows, and later versions than XP) that you can put on a USB stick or unzip out of a zipfile and run directly from there. I can't remember what it was called, and I think it went out of support half a decade ago, but there may be a newer equivalent. – abarnert Mar 19 '18 at 22:29

2 Answers2

2

In terms of speed that is little you can do. You could convert your Python script into a compiled extension, this increases speed of a Python script greatly. Cython can do this and once compile you then do as you have done already.

Honestly you will notice little difference if you do this, and that is about the best you will do with that method. A better method is to turn it into an executable directly.

What you are doing currantly is:

  • The batch command starts and executes (this is slow by itself). This starts the Python interpreter.

  • The Python interpreter loads the file and then starts.


You should use a tool such as Cx_Freeze or Pyinstaller to convert your script into an executable, then it could be run just like any other appliocation. You could also use Cython to achieve this.

You can use installers as well.

Community
  • 1
  • 1
Xantium
  • 11,201
  • 10
  • 62
  • 89
1

Are you using any libraries? A quick solution would be converting the python script to executable using py2exe. More details are also in this post.

   from distutils.core import setup
   import py2exe

   setup(console=['sample.py'])

And then run the command

C:\Tutorial>python setup.py py2exe
cacti5
  • 2,006
  • 2
  • 25
  • 33