davidfoerster / aptsources-cleanup

Detects and interactively deactivates duplicate Apt source entries and deletes sources list files without valid enabled source entries (as requested in https://askubuntu.com/a/762815/175814).
MIT License
667 stars 85 forks source link

SyntaxError: invalid syntax -> File "aptsources-cleanup-0.1.4.zip", line 1 PK ^ #8

Closed dmmarmol closed 6 years ago

dmmarmol commented 6 years ago

I'm using ElementaryOS 0.4.1 Loki and when I run sudo python3 -OEs aptsources-cleanup-0.1.4.zip over the .zip file of the release v0.1.4, I get this error message:

  File "aptsources-cleanup-0.1.4.zip", line 1
    PK
      ^
SyntaxError: invalid syntax
davidfoerster commented 6 years ago

That means that your Python interpreter tries to run the Zip archive directly instead of the __main__.py bootstrapper script within. Maybe this feature was disabled for this Python build?

What's the output of sudo which python3 and sudo python3 --version? I'd like to know if this is the Python version shipped with eOS.

npphases commented 6 years ago

@davidfoerster I'm facing the same issue.

Here is the output of sudo python3 --version & python3 --version

Python 3.6.5 & /usr/bin/python3

davidfoerster commented 6 years ago

Uh, did you replace the default Python 3 installation of the system in question? That's highly discouraged and the aptsources module required for aptsources-cleanup and shipped in the repositories is likely incompatible with it. eOS Loki is based on Ubuntu Xenial which ships Python 3.5.1 and as far as I can tell eOS doesn't supersede it. What's the output of dpkg-query -S /usr/bin/python3 | sed -e 's/:[^:]*$//;s/, /\n/g' | sort -u | xargs -rd '\n' -- apt-cache policy --?

In any case if execution of Zip archives like Python scripts fails you can try this rough equivalent:

sudo PYTHONPATH="$PWD/aptsources-cleanup-0.1.4.zip" python3 -OEs -m __main__
alexanderameye commented 6 years ago

Having the same issue.

I get this output when trying dpkg-query -S /usr/bin/python3 | sed -e 's/:[^:]*$//;s/, /\n/g' | sort -u | xargs -rd '\n' -- apt-cache policy --

python3-minimal: Installed: 3.5.1-3 Candidate: 3.5.1-3 Version table: *** 3.5.1-3 500 500 http://be.archive.ubuntu.com/ubuntu xenial/main amd64 Packages 100 /var/lib/dpkg/status

davidfoerster commented 6 years ago

Hmm, I have no idea how to explain that. Does the alternative

sudo PYTHONPATH="$PWD/aptsources-cleanup-0.1.4.zip" python3 -OEs -m __main__

work? If it does I could at least update the README accordingly.

Gelmo commented 6 years ago
gelmo@gelmo-laptop:~/Downloads$ sudo PYTHONPATH="/home/gelmo/Downloads/aptsources-cleanup.zip" python3 -OEs -m __main__
/usr/bin/python3: Error while finding module specification for '__main__' (ValueError: __main__.__spec__ is None)

gelmo@gelmo-laptop:~/Downloads/aptsources/aptsources-cleanup-0.1.4$ sudo ./aptsources-cleanup 
Traceback (most recent call last):
  File "./aptsources-cleanup", line 9, in <module>
    runpy.run_module('aptsources_cleanup', run_name='__main__')
  File "/usr/lib/python3.6/runpy.py", line 201, in run_module
    mod_name, mod_spec, code = _get_module_details(mod_name)
  File "/usr/lib/python3.6/runpy.py", line 142, in _get_module_details
    return _get_module_details(pkg_main_name, error)
  File "/usr/lib/python3.6/runpy.py", line 109, in _get_module_details
    __import__(pkg_name)
  File "/home/gelmo/Downloads/aptsources/aptsources-cleanup-0.1.4/src/aptsources_cleanup/__init__.py", line 33, in <module>
    __version__ = str(__version__())
  File "/home/gelmo/Downloads/aptsources/aptsources-cleanup-0.1.4/src/aptsources_cleanup/util/version/__init__.py", line 154, in get_version
    _version = version_info.load()
  File "/home/gelmo/Downloads/aptsources/aptsources-cleanup-0.1.4/src/aptsources_cleanup/util/version/__init__.py", line 101, in load
    return cls.from_repo(version)
  File "/home/gelmo/Downloads/aptsources/aptsources-cleanup-0.1.4/src/aptsources_cleanup/util/version/__init__.py", line 108, in from_repo
    import git
ModuleNotFoundError: No module named 'git'

Worked great from source after installing "python3-git". Ubuntu 18.04.

davidfoerster commented 6 years ago

@Gelmo: That's entirely unrelated to the original bug report. I created two new issue reports #9 and #10 based on your comment.

davidfoerster commented 6 years ago

Closing until more info from OP becomes available.