Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 上传到test.pypi.org后出现pip包错误_Python_Python 3.x_Pip_Pypi - Fatal编程技术网

Python 上传到test.pypi.org后出现pip包错误

Python 上传到test.pypi.org后出现pip包错误,python,python-3.x,pip,pypi,Python,Python 3.x,Pip,Pypi,我创建了一个pip包,如下所示 我的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_ema

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

我的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',
    ],
}

)
我已将此软件包上载到

在我使用安装包之后

pip install -i https://test.pypi.org/simple/ calculator_py
我已经用支票检查了包裹

pip list
当我尝试导入这个包时,它会给我以下错误

ModuleNotFoundError:没有名为“calculator\u py”的模块

计算.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()

如何解决此问题?

您可能需要在
设置工具中安装
软件包=['scripts']

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

否则,pip可能会尝试从
name=“calculator\u py”
猜出它,而您没有名为
calculator\u py
的程序包,请修复缩进。
calculator\u py
只是发行版的名称,您没有名为它的模块或程序包,因此无法导入任何内容。运行
pip show-f calculator\u py
查看安装了哪些文件<代码>计算
可执行文件应可用:用计算的
检查它。顺便说一句,calculate=calculator.scripts.calculate:main
无法工作,因为包中没有模块
calculator.scripts.calculate
。首先,有
scripts=['scripts/calculate.py'],
添加
scripts
packages=['scripts'],
。其次,
pip
不会从包名猜出模块名。