PyPI 包在所述包中找不到函数



我制作了一个名为'pyutils39'的python包。到目前为止,它有两个函数consoleask(问题)和reverse(文本)。它似乎上传OK,并在pypi上有一个页面。(https://pypi.org/project/pyutils39) .

我的问题

为了测试,我安装了.pip install pyutils39包。它似乎安装成功,并且进入Libsite-packages pyyutils39确实有该文件。但是,当我运行测试文件时,它在

下崩溃了。
Traceback (most recent call last):
File "c:Users<MY USER>AppDataLocalProgramsPythonPython39Scriptstest.py", line 2, in <module>
x = pyutils39.consoleask("Do you want to reverse hello?")
AttributeError: module 'pyutils39' has no attribute 'consoleask'

完全删除包的所有踪迹会导致错误'Module Not Found'(预期)。把包文件放到和测试文件相同的文件夹中就可以了。

What I have try

我重新安装了我的软件包,重新制作了测试文件,并在google和stack overflow中搜索了这个问题,但没有任何效果。

主要文件:

def reverse(data):
x = str(data)
datalen = len(data)
x = x[datalen::-1]
return x
def consoleask(question):
while True:
print(str(question)+' (Y/N)')
x = input()
if x.lower().startswith('y'):
return True
break
elif x.lower().startswith('n'):
return False
break

测试文件

import pyutils39
x = pyutils39.consoleask("Do you want to reverse hello?")
if x == True:
print(pyutils39.reverse("hello"))

py

import setuptools
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name="pyutils39",
version="0.1.3",
author="Enderbyte09",
author_email="enderbyte09@gmail.com",
description="A utilities package",
long_description=long_description,
py_modules=['/src/pyutils39/pyutils39.py'],
long_description_content_type="text/markdown",
url="https://github.com/Enderbyte-Programs/pyutils39",
project_urls={
"Bug Tracker": "https://github.com/Enderbyte-Programs/pyutils39/issues",
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
package_dir={"": "src"},
packages=setuptools.find_packages(where="src"),
python_requires=">=3.8",

)

我还不熟悉stackoverflow,所以如果有任何改进的方法,请告诉我。

问题是在setup.py中使用错误的包源指令。在setup()调用中,使用py_modules=['pyutils39.py']-py_modules声明单文件模块。现在它可能使用packages或类似的参数,将整个目录声明为一个模块。很难做出更明智的猜测,因为setup.py在repo中缺失。

对于当前的布局,这可能会工作:

from pyutils39 import pyutils39

最新更新