简体   繁体   English

将Python脚本移动到另一台计算机

[英]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_installpip安装该软件包,则会自动下载并安装依赖项。

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.

相关问题 相同的 python 脚本在一台计算机上工作,但在另一台计算机上不起作用 - Same python script works in one computer but not in another 嵌入在 python 脚本中的声音会在另一台计算机上播放吗? - Will sounds embedded in a python script play on another computer? Python:移至新电脑 - Python: moving to a new computer 如何将带有 mysql 数据库的 python 脚本部署到另一台计算机 - how does one deploy a python script with a mysql database to another computer 如何检查在小型网络中的另一台计算机上是否正在运行相同的python脚本? - How to check if a the same python script is running in another computer in a small network? 在另一台计算机上运行的python脚本的远程控制功能 - Remote control functions of a python script running on another computer 如何在另一台计算机上打包和运行包含 venvs 的 python 脚本 - How to packaging and run python script including venvs on another computer 在线监控python脚本的进度,或在我的手机上,或另一台计算机上 - Monitoring the progress of a python script online, or on my phone, or another computer 将项目从一台计算机移动到另一台 - Moving project from one computer to another 使用另一台计算机的 python 脚本在新计算机上安装 Python? - Installing Python on a fresh new computer using a python script from another one?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM