安装requirements.txt错误,语法错误 - python2

时间:2016-03-17 23:05:17

标签: python pip

我有这个requirements.txt文件:

Django==1.9.4
EbookLib==0.15
SpeechRecognition==3.3.3
argcomplete==1.1.0
argparse==1.2.1
beautifulsoup4==4.4.1
chardet==2.3.0
lxml==3.5.0
pdfminer==20140328
python-docx==0.8.5
python-pptx==0.5.8
requests==2.9.1
textract==1.4.0
wsgiref==0.1.2
xlrd==0.9.4

当我在virtualenv中运行$ pip install -r requirements.txt时出现以下错误:

    Collecting pdfminer==20140328 (from -r requirements.txt (line 9))
  Using cached pdfminer-20140328.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-ymmlp5sc/pdfminer/setup.py", line 3, in <module>
        from pdfminer import __version__
      File "/tmp/pip-build-ymmlp5sc/pdfminer/pdfminer/__init__.py", line 5
        print __version__
                        ^
    SyntaxError: Missing parentheses in call to 'print'

似乎这个文件是用python2编写的。

有没有办法解决这个问题以及要安装的所有要求?

修改: 如果我尝试在我的全局环境中安装它,没有问题。如果我在virtualenv中它首先尝试收集一些东西。它的行为不同......

2 个答案:

答案 0 :(得分:1)

所以我想你的pip来自python3?在这种情况下,没有简单的修复,因为库显然不兼容python3,即使错误的打印不起作用,这只是冰山一角。

你要么:

  1. 将您的应用降级为python2
  2. 查找可以执行相同操作的其他库
  3. 将库移植到python3。
  4. 将库移植到python3可能不像你想象的那样可怕,especially since it seems that someone started to work on that already但是我无法验证它有多成熟,但它肯定是一个开始。

答案 1 :(得分:1)

在python 3K中,print不是保留关键字,而是内置函数,所以你必须像下面这样使用它:

print("Hello world!")

如果您使用print作为关键字,解释器将引发异常:

SyntaxError: Missing parentheses in call to 'print'

你遇到这样的安装库的问题,就是这里的pdfminer,在python 3K环境下的python 2中实现。要解决此问题,您有两个解决方案:

  1. 找到该库的python 3K兼容版本。
  2. 使用python 2作为默认解释器创建virtualenv。
相关问题