简体   繁体   English

Unix命令行程序中的Python模块

[英]Python Modules in Unix Command Line Programs

I wrote a python script that acts as a Unix command line argument (if it's saved in the working directory). 我编写了一个python脚本,用作Unix命令行参数(如果它已保存在工作目录中)。

If I downloaded external modules to use in this script, would someone on the same network (who doesn't have this module installed on their computer) still be able to run the script from their computer? 如果我下载了要在此脚本中使用的外部模块,则同一网络上的某人(他们的计算机上未安装此模块)仍可以从其计算机上运行该脚本吗? If not, how can I get around this? 如果没有,我该如何解决?

Thanks in advance... Please let me know if there's anything I can clarify about my question. 在此先感谢...如果有任何我想澄清的问题,请告诉我。

If you import third-party modules in your script, then whoever runs it needs to have those available. 如果您在脚本中import第三方模块,则无论运行它的人都需要那些可用的模块。

The Python solution would be to make your script into a package that has a setup.py that specifies scripts and also requires your dependencies. Python解决方案将使您的脚本成为一个具有setup.py的程序包,该程序包指定scripts并且还requires您的依赖项。 When someone installs the package using python setup.py install or a package manager, it will put the script into a directory on the path, make it executable and adjust the shebang line for the local environment. 当有人使用python setup.py install或软件包管理器python setup.py install软件包时,它将把脚本放入路径中的目录,使其可执行并针对本地环境调整shebang行。

Eg: 例如:

from setuptools import setup
setup(
    name='name',
    version='1.0.0',
    scripts=['myscript_filename'],
    install_requires=['other_module'],
)

Note that a different system, entry_points is now recommended over scripts but it requires a different format - see the docs. 请注意,现在建议在scripts上使用其他系统entry_points ,但它需要使用不同的格式-请参阅文档。

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

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