python - 如何创建快照包?

标签 python ubuntu snapcraft

我正在尝试创建 Python 应用程序的快照包(侵入)。我已将它上传到 pypi,它 pip 安装在 Arch 和 Ubuntu 上,奇怪的是安装到 Arch 上的/usr/bin/trespass 和 Ubuntu 上的/usr/local/bin/trespass。

当我尝试构建快照时,它失败了。

这是我的第一个 pypi 包,也是第一次尝试。所以很有可能我做错了。

这是 Arch 上的 dev 目录

[grahams@CQ5110F trespass]$ tree
.
├── build
│   ├── lib
│   │   └── trespass
│   │       └── trespass.py
│   └── scripts-3.6
│       ├── trespass
│       └── trespass.py
├── dist
│   ├── trespass-0.6.5.4.tar.gz
│   └── trespass-0.6.5.5.tar.gz
├── License
├── MANIFEST
├── README.md
├── README.txt
├── setup.cfg
├── setup.py
└── trespass
    └── trespass

我的 setup.py 看起来像这样
from distutils.core import setup
setup(
  name = 'trespass',
  packages = ['trespass'], # this must be the same as the name above
  install_requires=[
    'numpy',
    'pygpgme',
    'pyperclip',
    'argparse',
  ],
  version = '0.6.5.5',
  description = 'A secure password keeper', 
  author = 'Graham Smith',
  author_email = 'gps1539@gmail.com',
  scripts = ['trespass/trespass'],
  license='GPL3',
  url = 'https://github.com/gps1539/trespass', # use the URL to the github repo
  download_url = 'https://github.com/gps1539/trespass/archive/0.1.tar.gz',
  keywords = ['testing', 'logging', 'example'], # arbitrary keywords
  classifiers = [],
)

在 Ubuntu 上,我的 snapcraft.yaml 看起来像这样。
name: trespass
version: '0.6.5.4' 
summary: A secure command line password keeper using gpg 
description: |

grade: devel
confinement: devmode

apps:
  trespass:
    command: usr/bin/trespass

parts:
  trespass:
    plugin: python
    python-version: python3
    source: https://github.com/gps1539/trespass/archive/0.1.tar.gz
    build-packages:
      - python3-gpgme
      - python3-numpy
      - python3-pyperclip

当我尝试构建时,我得到以下输出
root@graham-VirtualBox:~/trespass-snap/snap# sudo snapcraft clean
Cleaning up priming area
Cleaning up staging area
Cleaning up parts directory
root@graham-VirtualBox:~/trespass-snap/snap# sudo snapcraft
Preparing to pull trespass 
Hit http://us.archive.ubuntu.com/ubuntu artful InRelease                            
Get:1 http://security.ubuntu.com/ubuntu artful-security InRelease [76.7 kB]         
Get:2 http://us.archive.ubuntu.com/ubuntu artful-updates InRelease [78.6 kB]        
Hit http://us.archive.ubuntu.com/ubuntu artful-backports InRelease                  
Fetched 155 kB in 0s (0 B/s)                                                        
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libpython3.6-minimal_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libsqlite3-0_3.19.3-3_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libpython3.6-stdlib_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/gcc-7-base_7.2.0-8ubuntu3_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3.6_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3_3.6.3-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/mime-support_3.60ubuntu1_all.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libmpdec2_2.4.2-1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libexpat1_2.2.3-1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3.6-minimal_3.6.3-1ubuntu1_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/python3-minimal_3.6.3-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libpython3-stdlib_3.6.3-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/dh-python_2.20170125_all.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libreadline7_7.0-0ubuntu2_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libffi6_3.2.1-6_amd64.deb
Ignoring already existing file: /home/graham/.cache/snapcraft/stage-packages/apt/66f26b5c7004236fca9a758cf1145e852e35e7324ed76a2004e35368186a7648fc1d800421527a152edbd60f41ffd05d/var/cache/apt/archives/libssl1.0.0_1.0.2g-1ubuntu13.2_amd64.deb
Pulling trespass 
Downloading '0.1.tar.gz'|                                                            
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/graham/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 733kB/s 
  Saved ./parts/trespass/packages/pip-9.0.1-py2.py3-none-any.whl
Collecting setuptools
  Downloading setuptools-36.7.0-py2.py3-none-any.whl (482kB)
    100% |████████████████████████████████| 491kB 1.8MB/s 
  Saved ./parts/trespass/packages/setuptools-36.7.0-py2.py3-none-any.whl
Collecting wheel
  Downloading wheel-0.30.0-py2.py3-none-any.whl (49kB)
    100% |████████████████████████████████| 51kB 3.2MB/s 
  Saved ./parts/trespass/packages/wheel-0.30.0-py2.py3-none-any.whl
Successfully downloaded pip setuptools wheel
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/graham/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Collecting setuptools
Collecting wheel
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.7.0 wheel-0.30.0
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Preparing to build trespass 
Building trespass 
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/graham/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting pip
Collecting setuptools
Collecting wheel
Installing collected packages: pip, setuptools, wheel
Successfully installed pip-9.0.1 setuptools-36.7.0 wheel-0.30.0
The directory '/home/graham/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Staging trespass 
Priming trespass 
Traceback (most recent call last):
  File "/usr/bin/snapcraft", line 11, in <module>
    load_entry_point('snapcraft==2.34+17.10', 'console_scripts', 'snapcraft')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 564, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2662, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2316, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2322, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/__main__.py", line 19, in <module>
    run(prog_name='snapcraft')
  File "/usr/lib/python3/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 1043, in invoke
    return Command.invoke(self, ctx)
  File "/usr/lib/python3/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python3/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/__init__.py", line 110, in run
    ctx.forward(lifecyclecli.commands['snap'])
  File "/usr/lib/python3/dist-packages/click/core.py", line 553, in forward
    return self.invoke(cmd, **kwargs)
  File "/usr/lib/python3/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/snapcraft/cli/lifecycle.py", line 132, in snap
    project_options, directory=directory, output=output)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 349, in snap
    execute('prime', project_options)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 130, in execute
    _Executor(config, project_options).run(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 228, in run
    self._create_meta(step, part_names)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/lifecycle.py", line 269, in _create_meta
    self.config.snapcraft_yaml_path)
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 84, in create_snap_packaging
    packaging.write_snap_yaml()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 111, in write_snap_yaml
    snap_yaml = self._compose_snap_yaml()
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 276, in _compose_snap_yaml
    snap_yaml['apps'] = self._wrap_apps(self._config_data['apps'])
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 385, in _wrap_apps
    self._wrap_app(app, apps[app])
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 392, in _wrap_app
    app[k] = self._wrap_exe(app[k], '{}-{}'.format(k, name))
  File "/usr/lib/python3/dist-packages/snapcraft/internal/meta.py", line 365, in _wrap_exe
    with open(exepath, 'rb') as exefile:
FileNotFoundError: [Errno 2] No such file or directory: '/home/graham/trespass-snap/snap/prime/usr/bin/trespass'

原帖在这里,但是由于链接太多,snapcraft论坛阻止了该主题:https://forum.snapcraft.io/t/how-to-call-dependencies-in-snapcraft-yaml/2726/8

最佳答案

您的 setup.py 需要在 https://github.com/gps1539/trespass/archive/0.1.tar.gz 内用作源。

关于python - 如何创建快照包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47232260/

相关文章:

linux - 如何找到最大堆栈大小?

ubuntu - 如何读取文件A中的每一行/字符串,并在文件B中找到包含字符串的行并在ubuntu中删除它

qt - 如何从 Qt 项目构建 SNAP 包

ubuntu - 使用 Snapcraft 安装软件包时出现 "store.RevisionNotAvailable"错误

python - 如何将一些字符串粘贴到 Python 中的事件窗口?

Python NameError 麻烦

python - 为什么运行 celeryd 时会得到 "SyntaxError: Non-ASCII character '\xa 3'"?

python - 给定两个词,找出它们是否在同一个同义词集中

python - 将列表形式的字符串转换为整数列表

snapcraft - 快照包 : What is the purpose of the "staging" and "priming" steps?