Skip to main content
 首页 » 编程设计

python之无法使用 PyPi 正确发布模块

2024年12月31日10myhome

我正在尝试将我的模块发布到 PyPi,但我遇到了麻烦。它发布了,我可以通过 Pip 安装它,但我似乎无法找出正确的导入语句来实例化我的类。

这是我的 setup.py 文件,代码位于同一目录中的 discord_webhooks.py 中。 Here's the published package .

from setuptools import setup, find_packages 
 
long_description = open('README.md').read() 
 
    setup( 
      name='Discord Webhooks', 
      version='1.0.1', 
      packages=find_packages(exclude=['tests', 'tests.*']), 
      url='https://github.com/JamesIves/discord-webhooks', 
      author='James Ives', 
      author_email='iam@jamesiv.es', 
      description='Easy to use package for Python which allows for sending of webhooks to a Discord server.', 
      long_description=long_description, 
      license='MIT', 
      install_requires=[ 
        'requests==2.20.0' 
      ], 
      classifiers=[ 
        'Programming Language :: Python :: 3' 
      ], 
    ) 

在完成 pip install discord-webhooks 之后,我尝试了 import DiscordWebhooks 和 from discord_webhooks import DiscordWebhooks 但似乎都不起作用。任何帮助,将不胜感激!

请您参考如下方法:

我自己设法解决了这个问题。由于这是一个单文件模块,我需要在 setup.py 文件中使用 py_modules。

这是更新后的文件:

from setuptools import setup, find_packages 
 
long_description = open('README.md').read() 
 
setup( 
  name='Discord Webhooks', 
  version='1.0.3', 
  py_modules=['discord_webhooks'], 
  url='https://github.com/JamesIves/discord-webhooks', 
  author='James Ives', 
  author_email='iam@jamesiv.es', 
  description='Easy to use package for Python which allows for sending of webhooks to a Discord server.', 
  long_description=long_description, 
  license='MIT', 
  install_requires=[ 
    'requests==2.20.0' 
  ], 
  classifiers=[ 
    'Development Status :: 5 - Production/Stable', 
    'Environment :: Other Environment', 
    'Intended Audience :: Developers', 
    'License :: OSI Approved :: MIT License', 
    'Programming Language :: Python :: 3', 
    'Programming Language :: Python :: 3.6', 
  ], 
)