从setup.py安装,但modulenotfoundererror



我试图制作一个python包。这是我的包结构。

my-package  
├── README.md  
├── LICENSE  
├── .gitignore  
├── setup.py  
└── my-package  
├── __init__.py
└── other_files.py

in mysetup.py:

import io
import os
from setuptools import setup, find_packages, find_namespace_packages
with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name="new-package",    # This is the name of the package
version="1.0.0",      # The initial release version
author="Author Name", # Full name of the author
author_email='author@gmail.com',
url='https://github.com/Author/myPackage',
description="Short Descriptio",
long_description=long_description,      # Long description read from the the readme file
long_description_content_type="text/markdown",
packages=find_namespace_packages(),    # List of all python modules to be installed
classifiers=[
'Intended Audience :: Developers',
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
'Topic :: Software Development :: Internationalization',
],                                      # Information to filter the project on PyPi website
python_requires='>=3.5',                # Minimum version requirement of the package
install_requires=['requests','simplejson'],  # Install other dependencies if any
)

从根目录,我使用以下命令生成发行文件:

python setup.py sdist bdist_wheel

然后,我使用以下命令在虚拟环境中安装这个包,从包根目录:

python -m pip install -e .

安装后,如果我运行pip list,它显示我安装了这个包(new_package)。

但是当我尝试导入这个时,使用import new_package,它给我

ModuleNotFoundError: No module named 'new_package'

我已经在堆栈中搜索了类似的问题,但无法解决。

有什么帮助吗?

尝试将内部my-package文件夹重命名为my_package,因为连字符不是包的有效名称模块或进口

my-package  # root folder
├── README.md  
├── LICENSE  
├── .gitignore  
├── setup.py  
└── my_package  # HERE, this package   
├── __init__.py
└── other_files.py

重新构建并重新安装发行版

注意:根文件夹my-package的名称如果包含连字符并不重要,因为它意味着在pypi存储库上发布和pip命令安装包

相关内容

  • 没有找到相关文章

最新更新