上载到test.pypi.org

时间:2019-01-10 20:05:09

标签: python python-3.x pip pypi

我创建了一个如下所示的pip包

enter image description here

我的setup.py文件

import setuptools

with open('README.md') as f:
    long_description = f.read()

setuptools.setup(
    name="calculator_py",
    version="0.0.1",
    scripts=['scripts/calculate.py'],
    author="xxxxxxx",
    author_email="xxxx@gmail.com",
    description="",
    long_description=long_description,
    long_description_content_type='text/markdown',
    url="",
    license='MIT',
    classifiers=[
    'Development Status :: 5 - Production/Stable',
    'Programming Language :: Python',
    'Programming Language :: Python :: 2',
    'Programming Language :: Python :: 2.7',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.5',
    'Programming Language :: Python :: 3.6',
    'Programming Language :: Python :: 3.7',
    'Programming Language :: Python :: Implementation :: CPython',
    'Programming Language :: Python :: Implementation :: PyPy',
    'License :: OSI Approved :: MIT License',
    'Operating System :: OS Independent',

],
entry_points={
    'console_scripts': [
        'calculate=calculator.scripts.calculate:main',
    ],
}

)

我已将此软件包上传到https://test.pypi.org

在我使用以下工具安装软件包后

pip install -i https://test.pypi.org/simple/ calculator_py

我已使用

检查包裹
pip list

当我尝试导入此软件包时,它给我以下错误

ModuleNotFoundError:没有名为“ calculator_py”的模块

calculate.py文件

class calculate:

def __init__(self):
    pass

def add(self, arg1, arg2):
    return arg1 + arg2

def sub(self, arg1, arg2):
    return arg1 - arg2

def mul(self, arg1, arg2):
    return arg1 * arg2

def div(self, arg1, arg2):
    return arg1 / arg2

if __name__ == '__main__':
     calculate()

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

您可能需要在packages=['scripts']中使用setuptools.setup,例如

setuptools.setup(
    ...
    packages=['scripts'],
    ...
)

否则,点子可能会尝试从name="calculator_py" 猜测它,而您没有名为calculator_py的软件包。