简体   繁体   English

如何在没有必需的外部库模块的其他系统上运行Python代码?

[英]How can I run my Python code on other system which doesn't have the required external library module?

I have built a Python application using an external library (lxml-module). 我已经使用外部库(lxml-module)构建了Python应用程序。 This runs fine in my system. 这在我的系统中运行良好。 Is there any way to compile this code or package this code, so that I can run it in another system which does not have this external library (lxml-module) module installed in it? 有什么方法可以编译此代码或打包此代码,以便可以在未安装此外部库(lxml-module)模块的另一个系统中运行它?

If possible please give me a little reference on *.pyd also? 如果可能的话,还请给我关于* .pyd的一些参考吗?

PyInstaller would be a good way to go to package your code. PyInstaller是打包代码的好方法。

It works in a configure/make/build workflow (before which you setup a small spec file with different kinds of options). 它在配置/制作/构建工作流程中起作用(在此之前,您使用不同的选项设置了一个小规格文件)。 The external package will be shipped along with your application. 外部软件包将与您的应用程序一起提供。

lxml is supported in PyInstaller: http://www.pyinstaller.org/wiki/SupportedPackages . PyInstaller支持lxml: http ://www.pyinstaller.org/wiki/SupportedPackages。

As for being able to compile your code on another machine, Marcin had a good suggestion. 至于能够在另一台机器上编译代码, Marcin提出了一个很好的建议。

You can always copy the module to your local path and import it from there. 您始终可以将模块复制到本地路径,然后从那里导入。 Kind of what django did for json until it was included in the standard library. django为json做的事情,直到它被包含在标准库中为止。

This could do the trick: 这可以达到目的:

try:
    import lxml
except ImportError:
    import myownmodules.lxml as lxml

I know this is the less "high tech" approach but if the problem is simple enough this is what I would do without a blink. 我知道这是不太“高科技”的方法,但是如果问题很简单,这就是我会眨眼做的。

Besides .... our buddy Tim seems to agree: "If the implementation is easy to explain, it may be a good idea." 除了....我们的好友蒂姆(Tim)似乎也同意:“如果实现易于解释,那可能是个好主意。”

对于Windows使用py2exe打包,对于OSX使用py2app ,对于Linux使用cx_freeze

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将我的 Python 代码(其中有 pip 模块)发送给没有安装 Python 的朋友? - How can I send my Python Code (Which has pip modules) to a friend who doesn't have Python installed? 我无法运行python代码-> ModuleNotFoundError:没有名为“ flask_sqlalchemy”的模块 - I can't run my python code -> ModuleNotFoundError: No module named 'flask_sqlalchemy' 如果我想在另一台没有安装 python 的机器上运行包含模块的 python 代码,我可以这样做吗? - If I want to run python code that includes modules on another machine that doesn't have python installed, can I do this? 如何在 numba 或其他一些 Python 库中并行化我的 for 循环代码? - How can i parallelize my for loop code in numba or in some other library of python? 如何在 Sublime Text 中创建构建系统以在 IDLE shell 中运行我的 python 代码? - How can I create a build system in Sublime Text to run my python code in an IDLE shell? 如何获取没有 pip 的生产环境所需的 python 库/包? - How to get the python libraries/packages required to a production environment which doesn't have pip? 如何重新编写此Python操作,使其不会挂起我的系统? - How can I rewrite this Python operation so it doesn't hang my system? 我能否以某种方式合并这些类,这样我就不必一次又一次地编写它,并且我的 python 代码不会变得多余 - Can I somehow merge these classes such that I don't have to write this again and again and my python code doesn't get redundant 如何在Windows系统上运行Python代码? - How can I run Python code on a windows system? 使用外部 Python 库。 其他程序员如何运行我的代码? - Using external Python libraries. How do other programmers run my code?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM