2

I have create a python package, which runs fine with:

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

The file structure is:

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

The main.py looks like (I don't know how much I should show, hence this is not a minimal one):

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)

Now, I am trying it to make installable in system file, with a executable, so that, something like ./mkbib will launch the application(is this a good idea?). I have seen the standard way is to use a setup.py script. I tried to mimic that, and failed:

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',
        ],
    },
)

The python3 setup.py install shows obvious error:

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:

    ''

I have no previous experience with setup.py (I am from fortran and make domain); kindly help.

EDIT: Important In many places, I see, there exists a __init__.py file. Is that essential to run setup.py? In other words, since my code is running, do I need to make any change in the code to use setup.py?

UPDATE I did as suggested by Alex, but then it copies the full system to /usr/lib/python3.4/site-packages/, making it a library, rather then executable app (should be in /usr/[share/local]/bin), what I am looking for. Any idea?

BaRud
  • 3,055
  • 7
  • 41
  • 89
  • Follow this tutorial, it's very helpful: http://python-packaging.readthedocs.io/en/latest/minimal.html – Alex Hall May 20 '16 at 09:43
  • I case if is my package I used to used python setup develop :http://stackoverflow.com/questions/19048732/python-setup-py-develop-vs-install – Ali SAID OMAR May 20 '16 at 09:49

0 Answers0