【问题标题】:Python and Requests on Mac OS, reporting deployment events to StackdriverMac OS 上的 Python 和请求,向 Stackdriver 报告部署事件
【发布时间】:2014-06-02 15:55:34
【问题描述】:

我正在尝试从 http://support.stackdriver.com/customer/portal/articles/1491725-sending-code-deploy-events-to-stackdriver 运行此示例

import requests
import json

def submit_code_deploy_event():
    """ Submit a code deploy event to Stackdriver """

    headers = { 'content-type': 'application/json',
                'x-stackdriver-apikey': '<YOURAPIKEY>' }

    deploy_event = { 'revision_id': '87230611cdc7e5ff7723a91e715367c553ad1115',
                     'deployed_by': 'JoeyI',
                     'deployed_to': 'production',
                     'repository':  'prototype_dashboard' }

    resp = requests.post( 'https://event-gateway.stackdriver.com/v1/deployevent',
                          data=json.dumps(deploy_event),
                          headers=headers)

    assert resp.ok, 'Failed to submit code deploy event.'

if __name__ == '__main__':
    submit_code_deploy_event()

但我收到了这个错误:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import requests
ImportError: No module named requests

所以我跑了:

➜  pip install requests
Downloading/unpacking requests
  Downloading requests-2.3.0-py2.py3-none-any.whl (452kB): 452kB downloaded
Installing collected packages: requests
Successfully installed requests
Cleaning up...

但错误仍然存​​在:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    import requests
ImportError: No module named requests

在 Mac OS 上运行,python 2.75 想法? (感觉像个菜鸟)

【问题讨论】:

    标签: python macos import


    【解决方案1】:

    您是否安装了与系统不同的 python 解释器?使用 OSX 开发时有一个常见的问题,我建议安装virtualenv 并处理虚拟环境中的所有依赖项。

    这些其他的东西可以帮助你:

    • 使用which pip 定位 pip 并查看此内容以了解正在使用哪个 python 版本

    • 找到你的python版本(which python),看看它是否类似于pip环境

    • 如果您使用 macports 或 homebrew,请务必将默认 Python 解释器替换为这些版本(它不会自动)。

    【讨论】:

    • ➜ ~ which pip /usr/local/bin/pip ➜ ~ which python /usr/bin/python
    • 用文本编辑器打开 pip 脚本,看看使用的是哪个 python 版本,在我的例子中是:#!/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-13
    • 2022-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多