2

您好,我正在尝试安装python-twitter,其中一个依赖项HTTPLIB2给我带来了很多问题。我在互联网上上下搜索过,但也许我不知道正确的关键词是什么。这是问题所在。

我正在安装python-twitter. "pip install -r requirements.txt"例如,我通过安装或一一安装要求"pip install httplib2"。然后我跑"python setup.py install"。它很高兴,但随后"python setup.py test"失败,并出现错误import HTTPLIB2

python setup.py test
running test
running egg_info
writing requirements to python_twitter.egg-info/requires.txt
writing python_twitter.egg-info/PKG-INFO
writing top-level names to python_twitter.egg-info/top_level.txt
writing dependency_links to python_twitter.egg-info/dependency_links.txt
reading manifest file 'python_twitter.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching '.DS_Store'
writing manifest file 'python_twitter.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
File "setup.py", line 73, in <module>
    Main()
  File "setup.py", line 66, in Main
    setuptools.setup(**METADATA)
  File                            

……

<deleted these parts to save space>
    module = __import__('.'.join(parts_copy))
  File "/Users/ME/Downloads/python-twitter-1.0/twitter_test.py", line 30, in <module>
    import twitter
  File "/Users/ME/Downloads/python-twitter-1.0/twitter.py", line 65, in <module>
    import oauth2 as oauth
  File "/usr/local/lib/python2.7/site-packages/oauth2/__init__.py", line 32, in <module>
    import httplib2
  File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 347
    print('%s:' % h, end=' ', file=self._fp)
                    ^
SyntaxError: invalid syntax

但我认为打印错误是 python 2 和 3 之间的不兼容。为什么我得到这个,而我显然有 python 2.7(我检查并卸载并重新安装了 HTTPLIB2)。非常感谢您的帮助

4

2 回答 2

3

我有同样的问题。似乎是 python2.7 和 3.x 版本冲突问题,由

python2.7 -m pip install -t lib/ -r requirements.txt
于 2017-03-24T10:44:06.440 回答
2

Just in case, this happens when you install httplib2 with a python3 version of pip and then execute it with python2.

This happens for example when creating manually an environment with:

pip install -t lib/ -r requirements

As it happens when creating an AppEngine standard environment vendor folder.

This happens because contrary to most of the libraries, httplib2 has completely different versions for python2 and python3.

于 2016-06-09T23:30:42.853 回答