简体   繁体   English

将virtualenv中的Python脚本打包到Debian软件包中

[英]Package Python script in virtualenv into a Debian package

I'm going crazy with this. 我为此感到疯狂。 I have a small script witch simply tells me the firefox profile name. 我有一个小脚本,女巫只是告诉我Firefox档案名称。 As I said this is only a test, just for test how does it work until starting the real job. 正如我所说的,这只是一个测试,只是为了测试在开始真正的工作之前它是如何工作的。 What we need is to deploy this script into a deb package to install them in all clients in our company (ubuntu mate). 我们需要将该脚本部署到一个deb包中,以将其安装到我们公司的所有客户端(ubuntu mate)中。

I have to say that is the first time I work with python, so maybe the setup.py isn't correct either. 我不得不说这是我第一次使用python,因此setup.py也不正确。 I created a virtualenv in my izenpe folder, and installed a module with 我在izenpe文件夹中创建了virtualenv,并使用

pip install mozprofile

This is my folder structure: 这是我的文件夹结构:

izenpe/
  - izenpemiddleware.py
  - setup.py
  - debian/
      - compat
      - control
      - izenpemiddleware.triggers
      - rule

This is my izenpemiddleware.py 这是我的izenpemiddleware.py

import sys
import mozprofile

def main(args=None):
    "The main routine."""
    if args is None:
        args = sys.argv[1:]
    pro = mozprofile.Profile()

    print "Perfila da:\n"
    print "*************"
    print pro.profile
    print "*************"

if __name__ == "__main__":
    main()

And this is my setup.py (is it ok?): 这是我的setup.py(可以吗?):

#!/usr/bin/env python

from setuptools import setup
from setuptools import find_packages

Description = """/
izenpe
"""

# setup parameters
setup(name='izenpemiddleware',
      version='0.1',
      description='Mirefox-en izenpe middleware instalatu',
      long_description=Description,
      packages=find_packages(),
      author_email='iibarguren@pasaia.net',
      classifiers=["Programming Language :: Python :: 2.7",
                   "Development Status:: 1 - Alpha",
                   'Programming Language :: Python',
                   ],
      scripts=["izenpemiddleware.py"]
      )

I found this library https://github.com/benjaminirving/python-debian-packaging-example to generate deb packages from a virtualenv, so this is my config: 我发现这个库https://github.com/benjaminirving/python-debian-packaging-example可以从virtualenv生成deb包,所以这是我的配置:

debian/control: debian /控制:

Source: izenpe
Section: python
Priority: extra
Build-Depends: debhelper (>= 9), python, dh-virtualenv, python-all-dev
Standards-Version: 3.9.5

Package: izenpemiddleware
Architecture: any
Pre-Depends: dpkg (>= 1.16.1), python2.7-minimal, ${misc:Pre-Depends}
Depends: ${python:Depends}, ${misc:Depends}, python-pyside, python-numpy
Description: Izenpe ziurtagiriak Firefox-entzat instalatu.

debian/firefoxmiddleware.triggers debian / firefoxmiddleware.triggers

# Register interest in Python interpreter changes (Python 2 for now); and
# don't make the Python package dependent on the virtualenv package
# processing (noawait)
interest-noawait /usr/bin/python2.7

# Also provide a symbolic trigger for all dh-virtualenv packages
interest dh-virtualenv-interpreter-update

debian/rules: debian /规则:

#!/usr/bin/make -f
%:
    dh $@ --with python-virtualenv

override_dh_virtualenv:
    dh_virtualenv --setuptools \
    --extra-pip-arg --ignore-installed \
    --extra-pip-arg --no-dependencies \
    --use-system-packag

After that I generated a deb package with this command: 之后,我使用以下命令生成了一个deb包:

sudo dpkg-buildpackage -us -uc -b 

Debian package is created correctly. Debian软件包已正确创建。 I sent this file via scp to another computer installed with 我通过scp将此文件发送到了另一台装有

dpkg -i izenpemiddleware_0.1_amd64.deb

If I updatedb and find the script with locate izenpemiddleware.py the result is: 如果我updatedb并找到带有izenpemiddleware.py的脚本,则结果是:

/usr/share/python/izenpemiddleware/bin/izenpemiddleware.py

It seems that is installed correctly, but when I launch the script I've got an error: 似乎已正确安装,但启动脚本时出现错误:

root@portatil-001:~# python /usr/share/python/izenpemiddleware/bin/izenpemiddleware.py
Traceback (most recent call last):
  File "/usr/share/python/izenpemiddleware/bin/izenpemiddleware.py", line 2, in <module>
    import mozprofile
ImportError: No module named mozprofile

Am I missing something? 我想念什么吗? Any help will be appreciated. 任何帮助将不胜感激。

Your setup.py needs to state its install_requires . 您的setup.py需要声明其install_requires

setup(…
    install_requires=['mozprofile'],
    …

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

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