[英]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. 我想知道如果我编写一个Python脚本,在我的计算机上使用已安装的库(例如lxml),并且我想在另一台计算机上部署此脚本,我的选择是什么。
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? 当然在另一台机器上安装了Python是给定的但是我还必须安装我在脚本中使用的所有库,或者我可以只使用* .pyc文件吗?
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. 我顺便说一下Windows机器。
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) . 事情是....这个工作所需的库不会安静地使用pip或easy_install,因为它需要一个Windows安装程序(我在一些搜索后找到)或者在目标计算机上重建来源(女巫,我试图避免)。
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. 我认为有一些方法可以将pyc文件或其他东西移植到另一台PC上,并且该工作站上的解释器不会要求其上的依赖关系已经被转换为字节码。
If this is not possible, can anyone show me a guide of some sort for making windows package installers ? 如果这是不可能的,有人可以向我展示一些制作Windows软件包安装程序的指南吗?
You should create setup.py
for use with setuptools . 您应该创建
setup.py
以与setuptools一起使用。 Dependencies should be included in the field install_requires
. 依赖关系应包含在
install_requires
字段中。 Afterwards if you install that package using easy_install
or pip
, dependencies will be automatically downloaded and installed. 之后,如果使用
easy_install
或pip
安装该软件包,则会自动下载并安装依赖项。
You can also use distutils . 你也可以使用distutils 。 A basic
setup.py
looks as follows: 基本的
setup.py
看起来如下:
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 . 对于distutils和setuptools之间的差异,请参阅此问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.