我试着制作一个发布在我的GitHub上并帮助用户下载程序的依赖项,但最终,它所做的只是生成重复的文件。我希望(最终)有一个用户可以输入的包:
>>> import my_package
>>> my_package.main
但这不起作用。我看了几个不同的网站和不同的模板,但似乎对此毫无进展。
目录结构
Kodimer_Project├──许可证├──歧管.in├──Makefile├──自述.md├──requirements.txt├──setup.py└──wav2bin├── __版本__.py├──imgs│├──应用程序图标.gif│├──App_Icon.ico│└── __init__.py└──src├──绘图.py├──图形界面.py├──SplashScreen.py├── __init__.py├── __main__.py└──helper_functions.py
setup.py
发件人:https://github.com/kennethreitz/setup.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Note: To use the 'upload' functionality of this file, you must:
# $ pip install twine
import io
import os
import sys
from shutil import rmtree
from setuptools import find_packages, setup, Command
# Package meta-data.
NAME = 'wav2bin'
DESCRIPTION = 'GUI graphing tool used concurrently with lab.'
URL = 'https://github.com/jvanderen1/Kodimer_Project'
EMAIL = 'jvanderen1@gmail.com'
AUTHOR = 'Joshua Van Deren'
# What packages are required for this module to be executed?
REQUIRED = [
'matplotlib',
'numpy',
'scipy'
]
# The rest you shouldn't have to touch too much :)
# ------------------------------------------------
# Except, perhaps the License and Trove Classifiers!
# If you do change the License, remember to change the Trove Classifier for that!
here = os.path.abspath(os.path.dirname(__file__))
# Import the README and use it as the long-description.
# Note: this will only work if 'README.md' is present in your MANIFEST.in file!
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
LONG_DESCRIPTION = 'n' + f.read()
# Load the package's __version__.py module as a dictionary.
about = {}
with open(os.path.join(here, NAME, '__version__.py')) as f:
exec(f.read(), about)
class UploadCommand(Command):
"""Support setup.py upload."""
description = 'Build and publish the package.'
user_options = []
@staticmethod
def status(s):
"""Prints things in bold."""
print(' 33[1m{0} 33[0m'.format(s))
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
self.status('Removing previous builds…')
rmtree(os.path.join(here, 'dist'))
except OSError:
pass
self.status('Building Source and Wheel (universal) distribution…')
os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable))
self.status('Uploading the package to PyPi via Twine…')
os.system('twine upload dist/*')
sys.exit()
# Where the magic happens:
setup(
name=NAME,
version=about['__version__'],
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
author=AUTHOR,
author_email=EMAIL,
url=URL,
package_dir={'': 'wav2bin'},
packages=find_packages(exclude=('tests', 'docs')),
# If your package is a single module, use this instead of 'packages':
# py_modules=['mypackage'],
entry_points={
'gui_scripts': ['wav2bin = wav2bin.__main__:main'],
},
install_requires=REQUIRED,
python_requires='>=3',
include_package_data=True,
license='MIT',
classifiers=[
# Trove classifiers
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3 :: Only',
'Natural Language :: English',
'Topic :: Scientific/Engineering :: Human Machine Interfaces',
'Topic :: Software Development :: User Interfaces'
],
# $ setup.py publish support.
cmdclass={
'upload': UploadCommand,
},
)
wav2bin/src/__main__.py
代码段:
if __name__ == '__main__':
main()
在您对各种封装模块有了一定的经验后,您通常会决定您希望您的封装有多专业?你想在pypi上托管它吗?从github分发?把它传给朋友?
这就是你选择包装方法的方式,但首先你可能应该对现有的包装模块有一些经验,最流行的两个是:
- setuptools,这是我通常使用的工具,我链接了一个很好的教程
- distutils是一个旧的api来分发包,但它仍然存在,而且很好地了解
如果你认为这是一种过度的做法,并且你想要一种不那么专业的方法,你总是可以手动完成。
要么安装到python软件包文件夹,这对pip来说通常意味着输入软件包根文件夹,然后输入
pip安装。
如果您确定您的包裹,或
pip安装-e。
如果您仍然希望保持包的延展性,请在编辑模式下安装
或者在导入之前以其他方式将包放在python路径中是强制性的。