将 Python 脚本移动到另一台计算机 [英] Moving a Python script to another computer

查看:72
本文介绍了将 Python 脚本移动到另一台计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如果我编写一个 Python 脚本来使用我计算机上已安装的库(例如 lxml)并且我想在另一台计算机上部署这个脚本,我的选择是什么.

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.

当然,在另一台机器上安装 Python 是给定的,但我是否还必须安装我在脚本中使用的所有库,还是可以只使用 *.pyc 文件?

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?

顺便说一下,我说的是 Windows 机器.

I am talking about Windows machines by the way.

编辑-------------------

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

看完你的答案后,我想我应该添加这个:

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

事情是......这个工作所需的库不会安静地与 pip 或 easy_install 一起出现,因为它需要一个 Windows 安装程序(我在一些搜索后找到的女巫)或在从源(我试图避免的女巫)的目标计算机.

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) .

我认为有某种方法可以将 pyc 文件或其他内容移植到另一台电脑上,并且该站上的解释器不需要依赖它已经被翻译成字节码.

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.

如果这是不可能的,谁能给我看一份制作 Windows 软件包安装程序的指南?

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

推荐答案

您应该创建 setup.py 以与 设置工具.依赖项应包含在 install_requires 字段中.之后,如果您使用 easy_installpip,依赖会自动下载安装.

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.

这篇关于将 Python 脚本移动到另一台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆