简体   繁体   中英

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 ?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM