python 安装 py包_使用安装python包设置.py

本文讲述了作者在尝试使用setup.py创建一个可执行的Python应用安装包时遇到的问题,包括安装过程中关于.pth文件支持的错误以及安装路径与PYTHONPATH的冲突。作者寻求帮助以解决如何正确配置setup.py,使应用能够安装在系统的bin目录下作为可执行程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我创建了一个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)中),这就是我要找的。有什么想法吗?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值