【问题标题】:Struggling with making a Python module accessible via PyPi努力通过 PyPi 访问 Python 模块
【发布时间】:2015-09-29 06:09:46
【问题描述】:

不久前,我编写了一个简单的 Python 接口来使用 Pushwoosh 通知服务,它位于 https://github.com/Astutech/Pushwoosh-Python-library,我终于开始发布它,以便可以使用 Pip 安装它。这是我第一次向 PyPi 发布 Python 库,我有点糊涂。

尝试安装它会出现以下错误:

Collecting pushwoosh
  Using cached pushwoosh-1.0.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-5m3jj7uu/pushwoosh/setup.py", line 17, in <module>
        with open(path.join(here, 'DESCRIPTION.rst'), encoding='utf-8') as f:
      File "/usr/lib/python3.4/codecs.py", line 896, in open
        file = builtins.open(filename, mode, buffering)
    FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-build-5m3jj7uu/pushwoosh/DESCRIPTION.rst'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-5m3jj7uu/pushwoosh

看起来像是某种路径相关的问题。我不确定pushwoosh.py 的位置是否正确。但是如果我将它移动到pushwoosh/pushwoosh.py,并添加一个pushwoosh/__init__.py 文件,那么我需要将其导入如下:

from pushwoosh.pushwoosh import Pushwoosh

这显然不理想。从文档中我看不出我哪里出错了。我应该使用什么目录布局?

编辑:我现在已经解决了DESCRIPTION.rst 的问题,但除非我将pushwoosh.py 文件移动到pushwoosh 文件夹并添加__init__.py 文件,否则安装库实际上不会安装pushwoosh.py所以它不起作用。我怎样才能修改它以便我可以像这样导入它?

from pushwoosh import Pushwoosh

【问题讨论】:

标签: python pip pypi


【解决方案1】:

最后想通了。如果您将文件作为__init__.py 放在module_name 文件夹中,它就可以工作。

【讨论】:

    【解决方案2】:

    您可以将其放入您的 __init__py 文件中。

    from pushwoosh import Pushwoosh
    

    这使您可以像这样进行导入,而无需将所有内容打包到 init.py 文件本身中。

    from pushwoosh import Pushwoosh
    

    查看这篇文章http://mikegrouchy.com/blog/2012/05/be-pythonic-__init__py.html 的详细解释

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2023-03-07
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      相关资源
      最近更新 更多