I have a directory structure as:
tree
.
├── bin
│ └── mkbib.py
├── LICENSE
├── mkbib
│ ├── __init__.py #empty file
│ ├── menubar.ui #a xml file. where should I place it?
│ ├── menu.py
│ ├── pybib.py
│ └── view.py
├── mkbib.desktop.in #should be copied to /usr/local/applications
├── README
└── setup.py
with bin/mkbib.py is the main file, which imports the files in mkbib/. And in bin/mkbib.py, I use:
import mkbib.menu as menu
import mkbib.view as view
# import view
# import pybib
If all files are in same directory, last two lines are enough. I separated them as per the accepted answer here.
But, now, when I am trying to run the code, I am getting error:
File "mkbib.py", line 26, in __init__
self.TreeView = view.treeview()
NameError: name 'view' is not defined
My ultimate goal is to install the mkbib app in the /bin/, same as the question I have linked, but I don't have any success.
My setup.py is :
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',
url='https://github.com/rudrab/mkbib',
author='Rudra Banerjee',
author_email='[email protected]',
license='GPLv3',
packages=['mkbib'],
package_dir={'mkbib': 'mkbib'},
scripts=['bin/mkbib.py']
)
When I run setup.py, I get;
sudo python3 setup.py develop
running develop
running egg_info
writing top-level names to mkbib.egg-info/top_level.txt
writing mkbib.egg-info/PKG-INFO
writing dependency_links to mkbib.egg-info/dependency_links.txt
reading manifest file 'mkbib.egg-info/SOURCES.txt'
writing manifest file 'mkbib.egg-info/SOURCES.txt'
running build_ext
Creating /usr/lib/python3.5/site-packages/mkbib.egg-link (link to .)
mkbib 0.1 is already the active version in easy-install.pth
Installing mkbib.py script to /usr/bin
Installed /home/rudra/Devel/mkbib/Mkbib
Processing dependencies for mkbib==0.1
Finished processing dependencies for mkbib==0.1
I have also tried exporting pythonpath to the mkbib:
echo $PYTHONPATH
~/Devel/mkbib/Mkbib/mkbib
As I said, if all the files are in same directory, its working flawless.
The mkbib.py's structure is(as asked by GeckStar):
#!/usr/bin/python3
import gi
import sys
# import mkbib
import mkbib.menu as menu
import mkbib.view as view
# 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")
self.TreeView = view.treeview()
self.MenuElem = menu.MenuManager()
self.Parser = pybib.parser()
self.name = ""
.........
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)
Kindly help.
setup.py, to install the package?setup.pywith different file structure. Correct (atleast current)setup.pyand the run is included now. Kindly have a look.mkbib.pyfile, especially the first 26 lines since that's where the error happens.NameErroris being raised. It usually happens when you are using a function or class with an ambiguous name. I'd suggest you to try to importmkbib.viewwith another name, or change the name of themkbibfolder and see if it works then.buildthe system, now its giving ImportError for menu and others, if I run from out of Mkbib dir. This is because, the contents ofmkbibare placed inside abuild/lib, but not placed in /usr/lib/python3.5...