简体   繁体   English

分发依赖于包的Python脚本

[英]Distributing Python script which depends on a package

I wrote a script which makes use of Selenium, I installed Selenium through pip. 我写了一个使用Selenium的脚本,我通过pip安装了Selenium。 Is there a way that I can distribute this script to others without having them to install Selenium through pip? 有没有办法可以将这个脚本分发给其他人而无需通过pip安装Selenium?

I was looking at: 我在看:

https://pypi.python.org/pypi/selenium#downloads https://pypi.python.org/pypi/selenium#downloads

Would it help if I included the source distribution of Selenium from PyPI in my project folder? 如果我在项目文件夹中包含来自PyPI的Selenium的源代码分发,会有帮助吗? So that people just would have to click on the source distribution's install.py to install Selenium? 那么人们只需要点击源代码的install.py来安装Selenium?

You can use setuptools and use the install_requires keyword. 您可以使用setuptools并使用install_requires关键字。

Like this: 像这样:

from setuptools import setup

setup(
    # options
    install_requires = ['selenium'],
)

See the tutorial here 请参阅此处的教程

Then when they install your package/module using pip, selenium will also be installed. 然后,当他们使用pip安装包/模块时,也会安装selenium。

I wasn't able to find a real answer to this problem: 我无法找到这个问题的真正答案:

import os
import sys

os.system("python get-pip.py")

try:
    import pip
except ImportError:
    input('Could not install pip, please enter any key to quit this window.')
    sys.exit()


def install(package):
    pip.main(['install', package])

if __name__ == '__main__':
    install('selenium')

I did it like that, it makes use of pip. 我这样做了,它利用了点子。 Now people just can execute that script and both pip and selenium gets installed for them, however I'm unsure whether this is the right way to do it or not. 现在人们可以执行该脚本,并为他们安装了pipselenium ,但是我不确定这是否是正确的方法。

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

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