erocarrera / pefile

pefile is a Python module to read and work with PE (Portable Executable) files
MIT License
1.86k stars 519 forks source link

prevent installation of latest version on Python 2.7 #318

Open marunguy opened 3 years ago

marunguy commented 3 years ago

Windows 10 20H2 64bit, python 2.7.18.

In 2021.5.13 version, python 2.7 support is stopped. When I tried to install it on Python 2.7 I got the error below. I think that the previous version (2019.4.18) must be installed instead of the 2021.5.13 version.

py -2.7-32 -m pip install -U pefile
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Collecting pefile
  Using cached pefile-2021.5.13.tar.gz (66 kB)
    ERROR: Command errored out with exit status 1:
     command: 'D:\devtool\py27x86\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'d:\\users\\marunguy\\appdata\\local\\temp\\pip-install-ntlal5\\pefile\\setup.py'"'"'; __file__='"'"'d:\\users\\marunguy\\appdata\\local\\temp\\pip-install-ntlal5\\pefile\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base 'd:\users\marunguy\appdata\local\temp\pip-pip-egg-info-e2ku0w'
         cwd: d:\users\marunguy\appdata\local\temp\pip-install-ntlal5\pefile\
    Complete output (12 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "d:\users\marunguy\appdata\local\temp\pip-install-ntlal5\pefile\setup.py", line 86, in <module>
        long_description = "\n".join(_read_doc().split('\n')),
      File "d:\users\marunguy\appdata\local\temp\pip-install-ntlal5\pefile\setup.py", line 30, in _read_doc
        tree = ast.parse(f.read())
      File "D:\devtool\py27x86\lib\ast.py", line 37, in parse
        return compile(source, filename, mode, PyCF_ONLY_AST)
      File "<unknown>", line 3789
        f'Export directory contains more than 10 repeated entries '
                                                                  ^
    SyntaxError: invalid syntax
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
itamarst commented 3 years ago

The way to fix this is to:

  1. Yank the current release, whcih I think PyPI does these days?
  2. Add python_requires=">=3.6.0", to the setup() function in setup.py (assuming you have one, or just configure this metadata elsewhere).
  3. Do another release.

The result will be:

  1. Python 2 users get latest release that supports Python 2 (I encountered this working on project I'm helping port).
  2. Python 3 users get latest release.
digitalsleuth commented 3 years ago

Looks like the reason for this is the usage of the f-string interpolation which is only available in Python 3. However, modifying lines 3789 and 3790 to replace the f' string formatting with .format() then everything works as it should. These lines would now read:

'Export directory contains more than 10 repeated entries ' '({}, {:02x}). Assuming corrupt.'.format(symbol_name, symbol_address))

erocarrera commented 3 years ago

The way to fix this is to:

  1. Yank the current release, whcih I think PyPI does these days?
  2. Add python_requires=">=3.6.0", to the setup() function in setup.py (assuming you have one, or just configure this metadata elsewhere).
  3. Do another release.

The result will be:

  1. Python 2 users get latest release that supports Python 2 (I encountered this working on project I'm helping port).
  2. Python 3 users get latest release.

Thanks!! I'll do that.

digitalsleuth commented 3 years ago

Hi @erocarrera , The way to actually fix this error, is to fix the formatting issues which cause the error in python 2, as seen in PR #319. This will fix the installation issue for Python2.7. The fix methods above identified by @itamarst won't fix the cause of this issue, they will just allow the proper separation between Python 2 and Python 3.

erocarrera commented 3 years ago

Hi, I am no longer supporting Python 2. I prefer to focus the code on Python 3 and slowly take advantage of its features. I have yanked the version incompatible with Python 2 from PyPi, as suggested (thanks @itamarst ), so those systems can use a version that runs on them. All future fixes an improvements will only be tested to work under Python 3.

digitalsleuth commented 3 years ago

While I can appreciate that you no longer wish to support Python 2, and I understand it, it's a shame that you pulled the last release because all that was needed to leave that as the last Python 2 supported pefile was to fix the formatting on two lines, merging that pull request, and the 2021.5.13 release would have been the last python 2 release.

As it stands now, the last compatible python 2 release you left is from 2019, which doesn't have any of the features or updates you added in the last two years.

Either way, I appreciate your work on the project. Thank you.

erocarrera commented 3 years ago

Thank you for understanding, I wish I had the cycles to keep it compatible a while longer but I had to drop Python 2 at some point. I hope it's not too annoying for you, maybe extra motivation to move to Python 3? ;-)