使用setup.py安装python包

时间:2016-05-20 09:40:42

标签: python setup.py

我创建了一个python包,它运行正常:

python3 ~/Devel/mkbib/Python/src/main.py

文件结构为:

tree src/
src/
├── main.py
├── menubar.ui
├── menu.py
├── mkbib.svg
├── pybib.py
├── __pycache__
│   ├── main.cpython-34.pyc
│   ├── menu.cpython-34.pyc
│   ├── pybib.cpython-34.pyc
│   └── view.cpython-34.pyc
└── view.py

main.py看起来像(我不知道我应该展示多少,因此这不是最小的一个):

import gi
import sys
import menu
import view
import pybib
import urllib.parse as lurl
import webbrowser
import os
from gi.repository import Gtk, Gio  # , GLib, Gdk
gi.require_version("Gtk", "3.0")


class Window(Gtk.ApplicationWindow):
    def __init__(self, application, giofile=None):
        Gtk.ApplicationWindow.__init__(self,
                                       application=application,
                                       default_width=1000,
                                       default_height=200,
                                       title="mkbib")
...............
...............
class mkbib(Gtk.Application):
    def __init__(self):
        Gtk.Application.__init__(self)
        self.connect("startup", self.startup)
        self.connect("activate", self.activate)
..............
..............
def install_excepthook():
    """ Make sure we exit when an unhandled exception occurs. """
    old_hook = sys.excepthook

    def new_hook(etype, evalue, etb):
        old_hook(etype, evalue, etb)
        while Gtk.main_level():
            Gtk.main_quit()
        sys.exit()
    sys.excepthook = new_hook


if __name__ == "__main__":
    app = mkbib()
    r = app.run(sys.argv)
    sys.exit(r)

现在,我正在尝试使用可执行文件在系统文件中进行安装,这样./mkbib之类的内容将启动应用程序(这是一个好主意吗?)。我看到标准方法是使用setup.py脚本。我试图模仿,但失败了:

from setuptools import setup, find_packages
from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'README'), encoding='utf-8') as f:
    long_description = f.read()

setup(
    name='mkbib',
    version='0.1',
    description='BibTeX Creator',
    long_description=long_description,
    url='https://github.com/rudrab/mkbib',
    author='Rudra Banerjee',
    author_email='my email',
    license='GPLv3',
    classifiers=[
        'License :: OSI Approved :: GPL',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
        'Programming Language :: Python :: 3.5',
    ],

    keywords='BibTeX manager ',
    packages=find_packages(exclude=['contrib', 'docs', 'tests']),
    install_requires=['bibtexparser'],
    entry_points={
        'gui_scripts': [
            'mkbib=mkbib:main',
        ],
    },
)

python3 setup.py install显示明显错误:

export PYTHONPATH=${PYTHONPATH}:/opt
sudo python3 setup.py install --prefix=/opt
running install
Checking .pth file support in /opt/lib/python3.4/site-packages/
/bin/python3 -E -c pass
TEST FAILED: /opt/lib/python3.4/site-packages/ does NOT support .pth files
error: bad install directory or PYTHONPATH

You are attempting to install a package to a directory that is not
on PYTHONPATH and which Python does not read ".pth" files from.  The
installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /opt/lib/python3.4/site-packages/

and your PYTHONPATH environment variable currently contains:

    ''

我以前没有使用setup.py的经验(我来自fortranmake域名);善意的帮助。

编辑:重要在很多地方,我看到,存在一个__init__.py文件。运行setup.py至关重要吗?换句话说,由于我的代码正在运行,我是否需要对代码进行任何更改才能使用setup.py?

更新我按照Alex的建议做了,但随后它将整个系统复制到/usr/lib/python3.4/site-packages/,使其成为库,而不是可执行应用(应该在/usr/[share/local]/bin ),我在找什么。有什么想法吗?

0 个答案:

没有答案