dashingsoft / pyarmor

A tool used to obfuscate python scripts, bind obfuscated scripts to fixed machine or expire obfuscated scripts.
http://pyarmor.dashingsoft.com
Other
3.25k stars 277 forks source link

pyarmor and library dependencies #1652

Closed naarkhoo closed 8 months ago

naarkhoo commented 8 months ago

I am trying to obfuscate my codes using PyArmor 7; the code uses Librosa and appearance librosa also uses lazy_loader.

my code uses a series of code under xa_dsp_tools folder.

so I use

pyarmor obfuscate --recursive \
         --output dist/xa_dsp_tools xa_dsp_tools/__init__.py \

pyarmor obfuscate --recursive \
                        --output dist/src src/main.py \

this results in a dist folder mirroring these two src and xa_dsp_tools folder;

however when I run my code using python dist/src/main.py

I get

Traceback (most recent call last):
  File "/Users/alka/Library/Caches/pypoetry/virtualenvs/plusplus-ETvGGZ8p-py3.10/lib/python3.10/site-packages/lazy_loader/__init__.py", line 193, in load
    parent = inspect.stack()[1]
  File "/Users/alka/.pyenv/versions/3.10.5/lib/python3.10/inspect.py", line 1678, in stack
    return getouterframes(sys._getframe(1), context)
  File "/Users/alka/.pyenv/versions/3.10.5/lib/python3.10/inspect.py", line 1655, in getouterframes
    frameinfo = (frame,) + getframeinfo(frame, context)
  File "/Users/alka/.pyenv/versions/3.10.5/lib/python3.10/inspect.py", line 1627, in getframeinfo
    start = lineno - 1 - context//2
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "</Users/alka/Devel/8D/dist/src/main.py>", line 3, in <module>
  File "<frozen src.main>", line -1, in <module>
  File "<frozen src.utils>", line 64, in generate_custom_melspec
  File "/Users/alka/Library/Caches/pypoetry/virtualenvs/plusplus-ETvGGZ8p-py3.10/lib/python3.10/site-packages/lazy_loader/__init__.py", line 78, in __getattr__
    attr = getattr(submod, name)
  File "/Users/alka/Library/Caches/pypoetry/virtualenvs/plusplus-ETvGGZ8p-py3.10/lib/python3.10/site-packages/lazy_loader/__init__.py", line 77, in __getattr__
    submod = importlib.import_module(submod_path)
  File "/Users/alka/.pyenv/versions/3.10.5/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/alka/Library/Caches/pypoetry/virtualenvs/plusplus-ETvGGZ8p-py3.10/lib/python3.10/site-packages/librosa/core/audio.py", line 31, in <module>
    samplerate = lazy.load("samplerate")
  File "/Users/alka/Library/Caches/pypoetry/virtualenvs/plusplus-ETvGGZ8p-py3.10/lib/python3.10/site-packages/lazy_loader/__init__.py", line 203, in load
    del parent
UnboundLocalError: local variable 'parent' referenced before assignment

I wonder how.

I have asked this question here on stackoverflow as well

naarkhoo commented 8 months ago

@jondy may I asked what does documented mean here. I appreciate any hint, so I can look again through your PyArmor documentation. Thank you.

jondy commented 8 months ago

Please check the chapter understand the obufscated scripts https://pyarmor.readthedocs.io/en/v7.7.4/understand-obfuscated-scripts.html#the-differences-of-obfuscated-scripts

jondy commented 8 months ago

Also check https://pyarmor.readthedocs.io/en/latest/how-to/third-party.html

Though it's for Pyarmor 8, but it does for Pyarmor 7.7.4

ykk648 commented 2 months ago

just comment this two lines:

# samplerate = lazy.load("samplerate")
# resampy = lazy.load("resampy")

pyarmor do not support lazy_load