Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving a Python script to another computer

I am wondering what my options are if I write a Python script that makes use of installed libraries on my computer (like lxml for example) and I want to deploy this script on another computer.

Of course having Python installed on the other machine is a given but do I also have to install all the libraries I use in my script or can I just use the *.pyc file?

Are there any options for making an installer for this kind of problem that copies all the dependencies along with the script in question?

I am talking about Windows machines by the way.

Edit -------------------

After looking through your answers i thought i should add this:

The thing is....the library required for this to work won't come along quietly with either pip or easy_install on account on it requiring either a windows installer (witch i found after some searching) or being rebuilt on the target computer from sources (witch i'm trying to avoid) .

I thought there was some way to port a pyc file or something to another pc and the interpreter on that station will not require the dependencies on account on it already being translated to bytecode.

If this is not possible, can anyone show me a guide of some sort for making windows package installers ?

like image 1000
omu_negru Avatar asked Jan 17 '23 03:01

omu_negru


2 Answers

You should create setup.py for use with setuptools. Dependencies should be included in the field install_requires. Afterwards if you install that package using easy_install or pip, dependencies will be automatically downloaded and installed.

like image 141
vartec Avatar answered Jan 18 '23 23:01

vartec


You can also use distutils. A basic setup.py looks as follows:

from distutils.core import setup

setup(
    name='My App',
    version='1.0',
    # ... snip ...
    install_requires=[
        "somedependency >= 1.2.3"
    ],
)

For differences between distutils and setuptools see this question.

like image 22
armandino Avatar answered Jan 19 '23 00:01

armandino