我尝试在我的GitHub上发帖并帮助用户下载该程序的依赖项,但最后,它所做的只是生成重复文件。我希望(最终)有一个用户可以输入的包:
>>> import my_package
>>> my_package.main
但这不起作用。我看过几个不同的网站和不同的模板,但似乎无处可去。
Kodimer_Project ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── requirements.txt ├── setup.py └── wav2bin ├── __version__.py ├── imgs │ ├── App_Icon.gif │ ├── App_Icon.ico │ └── __init__.py └── src ├── DrawGraph.py ├── GraphicInterface.py ├── SplashScreen.py ├── __init__.py ├── __main__.py └── helper_functions.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('\033[1m{0}\033[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,
},
)
代码片段:
if __name__ == '__main__':
main()
答案 0 :(得分:0)
在您拥有各种包装模块的经验之后,您通常会做出决定您希望包装的专业程度的方法吗?你想在pypi上主持吗?从github分发它?把它传递给朋友?
这就是你选择包装方法的方法,但首先你应该对现有的包装模块有一些经验,最受欢迎的两个是:
如果那时你认为这是一种矫枉过正,你想要一种不太专业的方法,你总是可以手动完成。
安装到python包文件夹,pip通常意味着输入包根文件夹并输入
pip install。
如果您确定自己的套餐,或
pip install -e。
如果您仍希望保持包装可塑性,则在编辑模式下安装
或者在导入之前以其他方式将包放在python路径中是必需的。