scdl-org / scdl

Soundcloud Music Downloader
GNU General Public License v2.0
3.29k stars 331 forks source link

SyntaxError / possible python version mix-up #103

Closed bradenbest closed 8 years ago

bradenbest commented 8 years ago

I just did a fresh install of the current repository, and got this error upon attempting to run it.

./setup.py build
sudo ./setup.py install
scdl
Traceback (most recent call last):
  File "/usr/local/bin/scdl", line 9, in <module>
    load_entry_point('scdl==1.4.1', 'console_scripts', 'scdl')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2355, in load
    return self.resolve()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2361, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python2.7/dist-packages/scdl-1.4.1-py2.7.egg/scdl/scdl.py", line 60
    logger.newline = print
                         ^
SyntaxError: invalid syntax

Upon investigation, the directory scdl-1.4.1-py2.7.egg/ does not exist inside /usr/local/lib/python2.7/dist-packages/. So apparently python eggs are zip archives, (according to file scdl-1.4.1-py2.7.egg), but attempting to unzip it so I can investigate the contents fails.

Yeah, I don't understand python eggs / packaging at all. And there being two versions of python doesn't help.

Back to square 1. I checked out scdl/scdl.py:60 in the repo, and found the mentioned line:

57 logger = logging.getLogger(__name__)
58 logger.setLevel(logging.INFO)
59 logger.addFilter(utils.ColorizeFilter())
60 logger.newline = print
61 
62 arguments = None
63 token = ''

I have no idea why this is a syntax error. The syntax (object.name = other_name) seems perfectly valid to me. The only way this would make sense is if print is a keyword. But I thought it was an instance of some class, like libiostream's cout.

Well, for all I know, print probably is a keyword, and that's probably the reason the community fragmented python into two simultaneously active, incompatible versions. An absurd, illogical decision IMO. One should deprecate the other as the standard or at least be backward-compatible (like Java 6/7, C 89/99), not join it ala assembly language ... Sigh, I hate python.

I know in python3, it's perfectly valid since print is a function. But the error says it's python2.

No wait, line 1 says the interpreter is python3. And when I try to run scdl/scdl.py directly with python3, I get a different error:

Traceback (most recent call last):
  File "./scdl.py", line 47, in <module>
    import mutagen
ImportError: No module named 'mutagen'

That's nice, but installing mutagen will only fix the copy in the repo, not the copy in my /usr/local/bin, which is using python2... What?

I bet if I could investigate that egg, it would say python2. Why do I say that? Both because of the python-2.7 in the first error, and because if I run scdl/scdl.py with python2, I get this error:

python2 scdl.py 
  File "scdl.py", line 60
    logger.newline = print
                         ^
SyntaxError: invalid syntax

How familiar.

This fragmentation is really getting on my nerves. You don't get this kind of overcomplicated packaging scheme with other languages. Even though AutoTools is a pain in the ass, you usually only have to run ./configure and fix the errors until it works. Then you make && sudo make install and you're all good. Python? You gotta dig into a bunch of nearly-identical files all over the filesystem and figure out which one's missing a package, or which one's using the wrong version of python. This ends up being such a waste of time, that sometimes, I wonder if python is even worth it and why we don't all use perl. Yeah, perl. That shy, humble little language that no one seems to use or pay attention to except when it comes to string parsing and regex.

I eventually fixed this by using pip3 to install scdl, which is kind of annoying because I like bleeding edge. If I weren't afraid of rendering my computer un-bootable as a consequence of screwing around with that magical eldritch blackbox abomination we call UEFI, I'd be running Arch Linux instead of Ubuntu right now.

That said, at this point, I don't know if this issue is only affecting me, and the repo's fine, or if this is a real issue with the repo and somehow nobody's reported it. So my only option is to post this and leave the decision of close/investigate to the maintainer ( @flyingrub ).

Sorry for the long issue with a bunch of rants and tangents and rangents. Hopefully the above investigation helps.

Spotlight0xff commented 8 years ago

Your python command defaults to python2. I guess you could've installed it with sudo python3 ./setup.py install :) I reproduced this 'issue' with sudo python2 ./setup.py install. Btw, UEFI is not that bad ;) Running Arch with UEFI (rEFInd) just fine!

bradenbest commented 8 years ago

My python command defaults to python2, but setup.py's interpreter line says #!/usr/bin/env python3, so the command I used (./setup.py) is going to exec it with python3.

Spotlight0xff commented 8 years ago

https://github.com/flyingrub/scdl/blob/master/setup.py#L1 #!/usr/bin/env python where does it say python3? Just do a git clone and run sudo python3 ./setup.py install, done.

bradenbest commented 8 years ago

#!/usr/bin/env python #!/usr/bin/env python3

Ah. So it's not my fault. The versions are mixed up.

Python: it just works

Traceback (most recent call last):
  File "/usr/local/bin/scdl", line 9, in <module>
    load_entry_point('scdl==1.4.1', 'console_scripts', 'scdl')()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 558, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2682, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2355, in load
    return self.resolve()
  File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2361, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python2.7/dist-packages/scdl-1.4.1-py2.7.egg/scdl/scdl.py", line 60
    logger.newline = print

...provided that you can wrap your head around the packaging scheme, not forget which version you're using, not accidentally mix tabs and spaces, and depend on as little libraries as physically possible.