我已经制作了python包
https://github.com/raamana/pyradigm
并使用以下命令将其上传到pip
(遵循pypi上的说明等):
python setup.py sdist bdist_wheel
twine upload dist/*
理论上,现在应该可以做到
pip install pyradigm
(我可以确认是否有效)然后在Python文件中执行以下操作:
from pyradigm import MLDataset
使用MLDataset
pyradigm
不幸的是,情况并非如此,因为Python正在抛出以下ImportError
,这是非常不具体的:
In [1]: from pyradigm import MLDataset
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-4ad7330da13e> in <module>()
----> 1 from pyradigm import MLDataset
ImportError: cannot import name MLDataset
我可以确认
pyradigm
和类名MLDataset
)。 pyradigm中的setup.py是这样的:
#!/usr/bin/env python
import os
from setuptools import setup, find_packages
# Utility function to read the README file.
def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()
setup(name='pyradigm',
version='0.1.1.2',
description='Python-based data structure to improve handling of datasets in machine learning workflows',
long_description=read('README.md'),
keywords='machine learning, test dataset, python, workflow, provenance, data structure',
author='Pradeep Reddy Raamana',
url='https://github.com/raamana/pyradigm',
packages=find_packages(exclude=["*.tests", "*.tests.*", "tests.*", "tests"]), # packages=['pyradigm'],
install_requires=['numpy', 'setuptools'],
)
该软件包只有3个文件:
__init__.py pyradigm.py test_pyradigm.py
__init__.py
只包含一行:
__all__ = [ 'pyradigm', 'MLDataset' ]
理解此错误的任何帮助,以及修复它的方法将不胜感激。感谢。
答案 0 :(得分:1)
这是因为pyradigm
包中有pyradigm
个模块。
我已使用virtualenv
在pip install pyradigm
中安装了该软件包,并已成功导入MLDataset
from pyradigm.pyradigm import MLDataset
如果要导入为
from pyradigm import MLDataset
将您的__init__.py
更新为
from pyradigm import MLDataset