我正在尝试为python编写一个自定义包。它具有以下文件夹结构:
E:\GITHUB\FUNCTIONSYNTHESIZER
│ .gitignore
│ LICENSE
│ README.md
│ setup.py
│
├───docs
│ docs.md
│ Example-6-Points.png
│
└────src
│ function_synth.py
│ __init__.py
│
└───__pycache__
Pip允许通过setup.py的Folderpath进行安装。setup.py遵循Python.org的指导原则,最重要的是在另一个具有不同名称的包中工作:
from distutils.core import setup
def README():
return open("README.md").read()
setup(name='function_synthesizer',
version = '0.0.2',
description = 'Generates a polynomial interpolation from a set up points',
author = 'David J. Kowalk',
author_email = '...',
url = 'https://github.com/davidkowalk/FunctionSynthesizer',
license = "MIT",
keywords = "math interpolation polynomial calculus",
long_description = README(),
long_description_content_type='text/markdown',
classifiers=[
Calssifiers here
],
package_dir = {'':'src'},
python_requires = ">=3.6",
install_requires=['numpy'],
project_urls={
'Bug Reports': '...',
'Funding': '...',
'Source': '...',
}
)
__init__.py
导入函数_synth的不同函数
from function_synth import solve
from function_synth import to_str
from function_synth import calculate
该包由pip以setup.py定义的名称“function_synthesizer”安装,但当我运行pip show function_synthesizer
时
Name: function-synthesizer
Version: ...
此名称违反包名语法,最重要的是没有在任何地方定义。我找不到该破折号出现的任何原因,并且出于某种原因,它似乎替换了由name
参数定义的下划线。但是,即使我删除下划线并生成破折号,python也无法导入以下名称下的包:
是否存在从pip获取名称空间的方法,以及如何在setup.py中定义该名称空间
通过添加一个packages属性解决了此问题:
__init__.py
导入函数,然后通过相关问题 更多 >
编程相关推荐