我创建了一个python包,它可以很好地运行:python3 ~/Devel/mkbib/Python/src/main.py
文件结构为:
^{pr2}$
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(我来自fortran和{}域),请帮助。在
EDIT:Important在许多地方,我发现,存在一个__init__.py文件。这是运行setup.py所必需的吗?换句话说,由于我的代码正在运行,我是否需要对要使用的代码进行任何更改setup.py?在
更新我按照Alex的建议做了,但是它将整个系统复制到/usr/lib/python3.4/site-packages/,使之成为一个库,而不是可执行的应用程序(应该在/usr/[share/local]/bin)中),这就是我要找的。有什么想法吗?在