1

I have this requirements.txt file:

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

When I run $pip install -r requirements.txt in my virtualenv i have the following error:

    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'

It's seems that this file is written in python2.

Is there a way to fix this and all of the requirements to be installed ?

EDIT: If I try it to install in my global env, there is no problem. If I'm in virtualenv it first tries to collect something. It acts different ..

gneric
  • 3,457
  • 1
  • 17
  • 30

2 Answers2

1

So i guess that your pip is from python3? In that case there is no easy fix as the library is clearly not compatibile with python3, even the print in error is not going to work, and that is just top of the iceberg.

You will either have to:

  1. Downgrade your app to python2
  2. Find a different library that can do the same
  3. Port the library to python3.

Porting library to python3 may not be as scary as you think, especially since it seems that someone started to work on that already but I have no way of verifying how mature is that, but it for sure is a start.

Tymoteusz Paul
  • 2,732
  • 17
  • 20
  • It might be helpful to go over some of the less obvious parts of "Downgrade your app to python2"; in particular, the fact that OP's virtualenv is apparently running python3 is a blocker for this. – Kevin Mar 18 '16 at 03:19
1

In python 3K, print is not a reserved keyword, but a built-in function, so you must use it like below:

print("Hello world!")

If you use print as a keyword, the interpreter will raise an exception:

SyntaxError: Missing parentheses in call to 'print'

You encounter such problem for installing a library, namely, pdfminer here, implemented in python 2 under python 3K environment. To solve this problem, you have 2 solutions:

  1. Find the python 3K compatible version of the library.
  2. Make a virtualenv using python 2 as the default interpreter.
winiex
  • 125
  • 1
  • 8
  • Exactly, I checked my global env with 'python --version' and it's with 2.7.6. When I create a new virtualenv it's with 3.4. So I have to create it with default python2 interpreter like: http://stackoverflow.com/a/1534343/4990859 – gneric Mar 18 '16 at 08:39