Pokemon-Terminal icon indicating copy to clipboard operation
Pokemon-Terminal copied to clipboard

SyntaxError on macOS

Open neosalmon opened this issue 7 years ago • 9 comments

I encountered

 username@rootbox: pokemon _pikachu
Traceback (most recent call last):
  File "/usr/local/bin/pokemon", line 5, in <module>
    from pokemonterminal.main import main
  File "/Library/Python/2.7/site-packages/pokemonterminal/main.py", line 37
    print(f"Starting slideshow with {len(filtered)}, pokemon " +
                                                             ^
SyntaxError: invalid syntax

and:

username@rootbox: pokemon
Traceback (most recent call last):
  File "/usr/local/bin/pokemon", line 5, in <module>
    from pokemonterminal.main import main
  File "/Library/Python/2.7/site-packages/pokemonterminal/main.py", line 37
    print(f"Starting slideshow with {len(filtered)}, pokemon " +
                                                             ^
SyntaxError: invalid syntax

after a successful installation on macOS

neosalmon avatar Jun 30 '18 12:06 neosalmon

You need at least Python 3.6, your stack indicates you are using Python 2.7.

sylveon avatar Jun 30 '18 12:06 sylveon

That's strange, I do have python 3.7.0 installed via Homebrew

neosalmon avatar Jun 30 '18 12:06 neosalmon

Your method of installation seems to have installed it for Python 2.7. How did you install it?

sylveon avatar Jun 30 '18 19:06 sylveon

Initially, I was using the pre-installed version of Python, after which I ran brew install python to fetch the latest version.

neosalmon avatar Jul 03 '18 16:07 neosalmon

Just so I can keep in here for future reference:

Python got a lot of development in version 2 way too fast without much planning, which made a mess, which would involve making backwards incompatible changes in order to fix, but making such move so soon in the language would be too big of a shot in the foot, so they decided to maintain both versions, the 2 for legacy compatibility, and for butthurts who doesn't like change (it is open source after all people can keep python 2 alive forever), and 3 for all future development.

A lot of operating of operational systems, specially the more conservative ones which consider anything less then 3 years old is way too volatile, refused to (~~rewrite a lot of code~~) adapt to the new version. Which virtually makes python 2 the default, which is incompatible with our code that uses a lot of 3.6 features. e.g. fstrings:

Traceback (most recent call last):
  File "/usr/local/bin/pokemon", line 5, in <module>
    from pokemonterminal.main import main
  File "/Library/Python/2.7/site-packages/pokemonterminal/main.py", line 37
    print(f"Starting slideshow with {len(filtered)}, pokemon " +
                                                             ^
SyntaxError: invalid syntax

samuelhnrq avatar Jul 07 '18 13:07 samuelhnrq

My guess is that you used pip to install the pokemon-terminal package. The pip command on your system must default to the package installer for Python 2. You can explicitly use a more recent pip by adding a version number to the command, like so:

pip3 --help
# or
pip3.6 --help

I'm not that used to pip packaging, but it would be great to fail install (or warn) if we aren't installing to Python >= 3.6

sylveon avatar Jul 11 '18 02:07 sylveon

~~That's easy enough to do; you can put a check in your setup. Actually there's a package you can use as a dependency which literally just does this check for you: https://pypi.org/project/require-python-3/ though it seems a bit overkill for something you could write yourself in 2 lines.~~

Looks like there's an official way to do this now: https://packaging.python.org/guides/dropping-older-python-versions/

giftig avatar Jul 11 '18 21:07 giftig

That python_requires is already there in the setup.py

Since his python didn't catch it up (probably too outdated to support that key), we should add a few lines of manual check.

import sys
assert (sys.version_info.major >= 3 and sys.version_info.minor >= 6), "Pokémon-Terminal requires at least Python 3.6"

sylveon avatar Jul 11 '18 21:07 sylveon

It's supported by pip9+, current version is 10.0.1. It seems like an odd choice to me to deliberately drop support for python2.7 but attempt to support versions of pip two major versions out of date, but to each their own.

giftig avatar Jul 11 '18 21:07 giftig