packt-cli / Packt-Publishing-Free-Learning

Scripts that automatically claim and download free daily eBooks from https://www.packtpub.com/packt/offers/free-learning

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyntaxError: invalid syntax with python2

Mte90 opened this issue · comments

Traceback (most recent call last):
  File "/usr/local/bin/packt-cli", line 6, in <module>
    from packtPublishingFreeEbook import packt_cli
  File "/usr/local/lib/python2.7/dist-packages/packtPublishingFreeEbook.py", line 248
    end="", )
       ^
SyntaxError: invalid syntax

THe readme suggest pip but this in Debian means that will use python2, install with pip3 use python3 and now works.

Well, it depends. In general pip executable may point to pip inside Python 2.x or Python 3.x installation. For instance when I run less $(which pip) on my Debian mashine it runs indeed on Python 2.

oracle@batcave:~$ cat $(which pip)
#!/usr/bin/python
# GENERATED BY DEBIAN

import sys

# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
    sys.exit(main())

On the other hand if I run it inside my virtualenv I've got output below (it runs on Python 3).

(packt) oracle@batcave:~$ cat $(which pip)
#!/home/oracle/.virtualenvs/packt/bin/python3

# -*- coding: utf-8 -*-
import re
import sys

from pip._internal import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(main())

So it may depend on which Python installation is default on your mashine. How do you propose to change the wording in the README.md?

I think if we propose as command pip3 is difficult that people use the wrong command in all the cases.

Should we do anything with that or may we leave it as it is (and assume that user has some knowledge about Python)?

I think that if we write pip3 for install is the best option so is clear for everyone, for who has knowledge of python and also for newbie that copy and paste commands.

It won't work for people using virtualenv (which should be preferred way of installing the script).

So maybe it is possible to add another line that for virtualenv use [...] and for the other case use [...]

I was wrong - it will work for people using virtualenv, so I think it's reasonable to write to change installation command in README.md to pip3 install packt --upgrade.

Resolved by #152.