Sep-04-2019, 08:45 AM
Sep-04-2019, 08:50 AM
the real question is how you will enforce it and is it worth the efforts?
i.e. it's up to you under what license terms you will distribute your work (i.e. that's legal matter)
i.e. it's up to you under what license terms you will distribute your work (i.e. that's legal matter)
Sep-04-2019, 11:37 AM
You can put any license terms you want on your scripts. Like buran said, the trouble of enforcing it is usually not worth it. Anything can be reversed engineered. Even Windows exe files can be tapped into. But python's are much easier to break into as it was never intended to be closed software.
https://stackoverflow.com/questions/2616...ython-code
https://stackoverflow.com/questions/2616...ython-code
Sep-04-2019, 12:20 PM
You can work with importlib.ressources, which is not so painful.
Running the creation of exe-file:
Result:
C:\Users\Admin\Desktop\example_with_ressources λ tree /F Auflistung der Ordnerpfade Volumeseriennummer : 6CC1-07AC C:. │ test.py │ test.spec │ └───data test1.txt test2.txt test3.txt __init__.pytest.py
from importlib import resources import data # <- import of package with data files with resources.path(data, 'test1.txt') as p: print(p, type(p)) # <- pathlib object print(p.read_text()) print(resources.read_text(data, 'test2.txt')) print(resources.read_text(data, 'test3.txt'))test.spec
# -*- mode: python ; coding: utf-8 -*- block_cipher = None a = Analysis(['test.py'], pathex=['.'], binaries=[], datas=[ ('data/test1.txt', 'data'), ('data/test2.txt', 'data'), ('data/test3.txt', 'data'), ], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='test', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=True )The variable datas must be edited to copy non-python files into the executable file.
Running the creation of exe-file:
Output:λ pyinstaller.exe test.spec
49 INFO: PyInstaller: 3.5
49 INFO: Python: 3.7.4
49 INFO: Platform: Windows-10-10.0.18362-SP0
59 INFO: UPX is not available.
59 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Admin\\Desktop\\example_with_ressources',
'C:\\Users\\Admin\\Desktop\\example_with_ressources']
59 INFO: checking Analysis
59 INFO: Building Analysis because Analysis-00.toc is non existent
59 INFO: Initializing module dependency graph...
59 INFO: Initializing module graph hooks...
59 INFO: Analyzing base_library.zip ...
2122 INFO: running Analysis Analysis-00.toc
2132 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\program files\python37\python.exe
2958 INFO: Caching module hooks...
2958 INFO: Analyzing test.py
3011 INFO: Loading module hooks...
3011 INFO: Loading module hook "hook-encodings.py"...
3071 INFO: Loading module hook "hook-pydoc.py"...
3071 INFO: Loading module hook "hook-xml.py"...
3228 INFO: Looking for ctypes DLLs
3228 INFO: Analyzing run-time hooks ...
3238 INFO: Looking for dynamic libraries
4628 INFO: Looking for eggs
4628 INFO: Using Python library c:\program files\python37\python37.dll
4628 INFO: Found binding redirects:
[]
4638 INFO: Warnings written to C:\Users\Admin\Desktop\example_with_ressources\build\test\warn-test.txt
4658 INFO: Graph cross-reference written to C:\Users\Admin\Desktop\example_with_ressources\build\test\xref-test.html
4668 INFO: Appending 'datas' from .spec
4678 INFO: checking PYZ
4678 INFO: Building PYZ because PYZ-00.toc is non existent
4678 INFO: Building PYZ (ZlibArchive) C:\Users\Admin\Desktop\example_with_ressources\build\test\PYZ-00.pyz
5029 INFO: Building PYZ (ZlibArchive) C:\Users\Admin\Desktop\example_with_ressources\build\test\PYZ-00.pyz completed successfully.
5038 INFO: checking PKG
5038 INFO: Building PKG because PKG-00.toc is non existent
5038 INFO: Building PKG (CArchive) PKG-00.pkg
6165 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
6165 INFO: Bootloader C:\Users\Admin\AppData\Roaming\Python\Python37\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
6165 INFO: checking EXE
6165 INFO: Building EXE because EXE-00.toc is non existent
6165 INFO: Building EXE from EXE-00.toc
6165 INFO: Appending archive to EXE C:\Users\Admin\Desktop\example_with_ressources\dist\test.exe
6241 INFO: Building EXE from EXE-00.toc completed successfully.
Output:C:\Users\Admin\Desktop\example_with_ressources
λ dist\test.exe
C:\Users\Admin\AppData\Local\Temp\_MEI110682\data\test1.txt <class 'pathlib.WindowsPath'>
test
x
Hi