【问题标题】:Does unirest support python3?unirest 支持 python3 吗?
【发布时间】:2015-03-30 20:02:22
【问题描述】:

unirest 支持 python3 吗?我用谷歌搜索了零信息。即使在the unirest documentation 中,它也没有说它只是 2.x,这让我相信它同时支持 3.x 和 2.x。但是安装失败并使用 3.4 并成功使用 2.7。见下文。

nkltss:~/dev$ mkvirtualenv mashape -p /usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in mashape/bin/python3
Also creating executable in mashape/bin/python
Installing setuptools, pip...done.


(mashape)nkltss:~/dev$ pip install unirest
Downloading/unpacking unirest
  Downloading Unirest-1.1.6.tar.gz
  Running setup.py (path:/home/nick/.virtualenvs/mashape/build/unirest/setup.py) egg_info for package unirest

    warning: no files found matching '*.txt' under directory 'docs'
Downloading/unpacking poster>=0.8.1 (from unirest)
  Downloading poster-0.8.1.tar.gz
  Running setup.py (path:/home/nick/.virtualenvs/mashape/build/poster/setup.py) egg_info for package poster
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/home/nick/.virtualenvs/mashape/build/poster/setup.py", line 2, in <module>
        import poster
      File "/home/nick/.virtualenvs/mashape/build/poster/poster/__init__.py", line 29, in <module>
        import poster.streaminghttp
      File "/home/nick/.virtualenvs/mashape/build/poster/poster/streaminghttp.py", line 61
        print "send:", repr(value)
                    ^
    SyntaxError: invalid syntax
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/home/nick/.virtualenvs/mashape/build/poster/setup.py", line 2, in <module>

    import poster

  File "/home/nick/.virtualenvs/mashape/build/poster/poster/__init__.py", line 29, in <module>

    import poster.streaminghttp

  File "/home/nick/.virtualenvs/mashape/build/poster/poster/streaminghttp.py", line 61

    print "send:", repr(value)

                ^

SyntaxError: invalid syntax

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /home/nick/.virtualenvs/mashape/build/poster
Storing debug log for failure in /home/nick/.pip/pip.log

目前我使用的是 2.7,但我更喜欢将 3.x 用于新项目。

【问题讨论】:

  • 我认为你应该使用pip3,它是python 3的pip版本。
  • @Krishath 使用了 pip3,同样的错误
  • 如果项目使用print,它可能不兼容 Python 3,不。

标签: python-3.x unirest


【解决方案1】:

该项目不兼容 Python 3。当项目没有明确说明这一点时(不在setup.py trove 分类器或文档中),您必须查看source code

我找到了:

项目依赖poster library,也就是urllib2 specific

我会改用requests library。它开箱即用地支持 Python 3,除了异步请求外,它还支持相同的功能集(但更好,因为它没有 urllib2 带来的缺点)。对于异步请求,您可以添加requests-futures

【讨论】:

  • 谢谢。 mashape 发布了一个相对较新的库,而且它只是 python2,这对我来说有点疯狂。我想我只是要使用 requests 库并跳过这个。
  • 该库声称的大部分功能在requests project 中也可用;异步部分是用线程实现的,requestsbetter options 用于异步工作。 requests 在 Python 3 上运行良好。
猜你喜欢
  • 1970-01-01
  • 2013-07-15
  • 2017-12-23
  • 2015-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-23
相关资源
最近更新 更多