安装的python包提供modulenotfound

2024-09-30 06:14:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我将一个包推送到pypip,然后成功地安装了它。 因为我在anaconda上,所以我可以conda list并确认我的包安装在基本环境中。在

接下来我要使用它:

from epicprint import Print

但这会抛出一个ModuleNotFoundError:没有名为“epicprint”的模块

我想我的包结构有一些错误。在我的测试.py奇怪的文件。请参阅以下文件包回购:

在打印.py

^{pr2}$

__初始py

from Print import Print

在设置.py

import setuptools
with open("README.md", "r") as fh:
    long_description = fh.read()
setuptools.setup(
     name='epicprint',  
     version='0.1',
     author="abc",
     author_email="abc@abc.com",
     description="Custom print with superpowers",
     url="https://github.com/ajthinking/print",
     packages=setuptools.find_packages(),
     classifiers=[
         "Programming Language :: Python :: 3",
         "License :: OSI Approved :: MIT License",
         "Operating System :: OS Independent",
     ],
 )

在测试.py

from Print import Print

print = Print()

print.info("Welcome").group()
print.success("Now we can:", ["Indent stuff", "Use colors", "Attach semantic to the print statements"])
print.warning("Nothing more to say")
print.reset().fail("Ending with a fail message. Bye.")

除了一个.whl和一个文件外,所有文件都在repo的根目录下。焦油gz在运行安装脚本后在dist文件夹以及build和egg info文件夹中找到。在

├── LICENSE
├── Print.py
├── README.md
├── __init__.py
├── __pycache__
│   └── Print.cpython-37.pyc
├── build
│   └── bdist.macosx-10.7-x86_64
├── dist
│   ├── epicprint-0.1-py3-none-any.whl
│   └── epicprint-0.1.tar.gz
├── epicprint.egg-info
│   ├── PKG-INFO
│   ├── SOURCES.txt
│   ├── dependency_links.txt
│   └── top_level.txt
├── setup.py
└── test.py

我哪里出错了?在


Tags: 文件frompyimportinfotxtwithmd
1条回答
网友
1楼 · 发布于 2024-09-30 06:14:56

您没有任何包目录(带有__init__.py的子目录),因此setuptools.find_packages()返回一个空列表,因此您的发行版不包含也不安装任何python模块或包。在

Print.py安装为独立模块:

setuptools.setup(
    …
    # packages=setuptools.find_packages(),
    py_modules=['Print.py'],
    …
)

或者将Print.py__init__.py移到子目录epicprint/,然后setuptools.find_packages()返回{}包,发行版将捕获它。在

在后一种情况下,test.py必须进行调整:

^{pr2}$

您是否希望test.py加入epicprint/软件包由您决定。在

相关问题 更多 >

    热门问题