python 安装 py包_使用安装python包设置.py 我不是女神ヾ 2022-10-31 13:50 227阅读 0赞 我创建了一个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)中),这就是我要找的。有什么想法吗?在
还没有评论,来说两句吧...