【问题标题】:Python-Instagram API example not workingPython-Instagram API 示例不起作用
【发布时间】:2014-10-09 22:04:57
【问题描述】:

我希望使用 Python-Instagram 包。我已经使用https://github.com/Instagram/python-instagram 上提供的脚本下载了包。

我尝试了提供的脚本之一。但是,我得到了同样的错误:ImportError: No module named client

from instagram.client import InstagramAPI

access_token = "YOUR_ACCESS_TOKEN"
api = InstagramAPI(access_token=access_token)
recent_media, next_ = api.user_recent_media(user_id="userid", count=10)
for media in recent_media:
     print media.caption.text

什么是模块客户端,如何安装?我已经在 IG 注册了一个客户。

【问题讨论】:

    标签: python instagram


    【解决方案1】:

    您是否在文件中添加了“instagram”名称?这可能是你的问题。

    看到这个link,描述了同样的错误,我意识到我的错误。

    【讨论】:

    • 同样的事情也发生在我身上。您应该删除所有名为“instagram”的文件,包括不可见的 instagram.py~ 和 instagram.pyc~
    【解决方案2】:

    我刚刚遇到了同样的问题,结果发现我的文件名为 instagram.py 与出现此错误的文件位于同一个包中。所以,这只是名称冲突。我重命名了本地文件,一切正常。

    【讨论】:

      【解决方案3】:

      推荐方式:

      1. 确保您拥有pip installed
      2. 使用以下命令安装软件包:pip install python-instagram(您可能需要管理员/sudo 权限)

      手动安装:

      1. https://github.com/Instagram/python-instagram下载压缩文件
      2. instagram 目录复制到您的python 的dist-package 目录或site-package 目录(与您相关的任何内容)

      然后您应该能够使用

      导入 InstagramAPI
      from instagram.client import InstagramAPI
      

      【讨论】:

      • Pip 还是 python instagram?哪个不工作?您使用的是哪种操作系统?
      • 抱歉不清楚。我确实使用了 pip install python-instagram。它安装正确。我使用的是 Mac OS X 10.9.5
      • 我在 ubuntu 中,但这对于 Mac OS X 应该是一样的:import instagram 然后dir(instagram) 应该列出['InstagramAPI', 'InstagramAPIError', 'InstagramClientError', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'bind', 'client', 'helper', 'json_import', 'models', 'oauth2']。有没有发现什么遗漏?
      【解决方案4】:

      你可能会像我一样来到这里,甚至有

      from InstagramAPI import InstagramAPI
      

      其他一切都正确设置我仍然得到错误:

      ImportError: No module named InstagramAPI
      

      我愚蠢到将 InstagramAPI 安装在一个 venv 中,并使用另一个 venv 来运行我的项目...... dah

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-05-25
        • 2014-03-03
        • 1970-01-01
        相关资源
        最近更新 更多