pyocd / pyOCD

Open source Python library for programming and debugging Arm Cortex-M microcontrollers
https://pyocd.io
Apache License 2.0
1.13k stars 484 forks source link

Build PyInstaller error #1004

Open zhepoch opened 4 years ago

zhepoch commented 4 years ago

I'm tried on python3.8, But not work.

Traceback (most recent call last):
  File "pyocd/tools/pyocd.py", line 23, in <module>
ImportError: attempted relative import with no known parent package
[50681] Failed to execute script pyocd

pip list:

Package                   Version            Location             
------------------------- ------------------ ---------------------
altgraph                  0.17               
appdirs                   1.4.3              
CacheControl              0.12.6             
certifi                   2019.11.28         
cffi                      1.14.3             
chardet                   3.0.4              
cmsis-pack-manager        0.2.10             
colorama                  0.4.3              
contextlib2               0.6.0              
distlib                   0.3.0              
distro                    1.4.0              
future                    0.18.2             
html5lib                  1.0.1              
idna                      2.8                
intelhex                  2.3.0              
intervaltree              3.1.0              
ipaddr                    2.2.0              
lockfile                  0.12.2             
milksnake                 0.1.5              
msgpack                   0.6.2              
naturalsort               1.5.1              
packaging                 20.3               
pep517                    0.8.2              
pip                       20.0.2             
pkg-resources             0.0.0              
prettytable               1.0.1              
progress                  1.5                
psutil                    5.7.3              
pycparser                 2.20               
pyelftools                0.27               
pyinstaller               4.1.dev0           
pyinstaller-hooks-contrib 2020.10            
pylink-square             0.8.1              
pyocd                     0.28.1.dev54+dirty /media/psf/work/pyOCD
pyparsing                 2.4.6              
pytoml                    0.1.21             
pyusb                     1.1.0              
PyYAML                    5.3.1              
requests                  2.22.0             
retrying                  1.3.3              
setuptools                44.0.0             
six                       1.14.0             
sortedcontainers          2.3.0              
urllib3                   1.25.8             
wcwidth                   0.2.5              
webencodings              0.5.1              
wheel                     0.34.2  

Build log:

120 INFO: PyInstaller: 4.1.dev0
120 INFO: Python: 3.8.5
132 INFO: Platform: Linux-5.4.0-52-generic-x86_64-with-glibc2.29
134 INFO: wrote /media/psf/work/pyOCD/flash_tool.spec
138 INFO: UPX is not available.
144 INFO: Extending PYTHONPATH with paths
['/media/psf/work/pyOCD', '/media/psf/work/pyOCD']
239 INFO: checking Analysis
263 INFO: Building because /media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py changed
263 INFO: Initializing module dependency graph...
272 INFO: Caching module graph hooks...
303 INFO: Analyzing base_library.zip ...
3024 INFO: Processing pre-find module path hook distutils from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
3026 INFO: distutils: retargeting to non-venv dir '/usr/lib/python3.8'
6478 INFO: Caching module dependency graph...
6646 INFO: running Analysis Analysis-00.toc
6678 INFO: Analyzing /media/psf/work/pyOCD/pyocd/tools/flash_tool.py
6891 INFO: Processing module hooks...
6892 INFO: Loading module hook 'hook-difflib.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
6895 INFO: Excluding import of doctest from module difflib
6896 INFO: Loading module hook 'hook-distutils.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
6900 INFO: Loading module hook 'hook-distutils.util.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
6902 INFO: Excluding import of lib2to3.refactor from module distutils.util
6902 INFO: Loading module hook 'hook-encodings.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
6978 INFO: Loading module hook 'hook-heapq.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
6984 INFO: Excluding import of doctest from module heapq
6984 INFO: Loading module hook 'hook-lib2to3.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
6998 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
7000 INFO: Excluding import of test from module multiprocessing.util
7000 INFO: Excluding import of test.support from module multiprocessing.util
7001 INFO: Loading module hook 'hook-pickle.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
7004 INFO: Excluding import of argparse from module pickle
7004 INFO: Loading module hook 'hook-sysconfig.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
7016 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
7018 INFO: Loading module hook 'hook-xml.py' from '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks'...
7152 INFO: Looking for ctypes DLLs
7180 INFO: Analyzing run-time hooks ...
7184 INFO: Including run-time hook '/media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py'
7200 INFO: Looking for dynamic libraries
7532 INFO: Looking for eggs
7532 INFO: Python library not in binary dependencies. Doing additional searching...
7592 INFO: Using Python library /lib/x86_64-linux-gnu/libpython3.8.so.1.0
7599 INFO: Warnings written to /media/psf/work/pyOCD/build/flash_tool/warn-flash_tool.txt
7642 INFO: Graph cross-reference written to /media/psf/work/pyOCD/build/flash_tool/xref-flash_tool.html
7658 INFO: checking PYZ
7663 INFO: Building because toc changed
7663 INFO: Building PYZ (ZlibArchive) /media/psf/work/pyOCD/build/flash_tool/PYZ-00.pyz
8076 INFO: Building PYZ (ZlibArchive) /media/psf/work/pyOCD/build/flash_tool/PYZ-00.pyz completed successfully.
8081 INFO: checking PKG
8094 INFO: Building because toc changed
8094 INFO: Building PKG (CArchive) PKG-00.pkg
10849 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
10852 INFO: Bootloader /media/psf/work/pyOCD/env/lib/python3.8/site-packages/PyInstaller/bootloader/Linux-64bit/run
10852 INFO: checking EXE
10893 INFO: Building because toc changed
10894 INFO: Building EXE from EXE-00.toc
10914 INFO: Appending archive to ELF section in EXE /media/psf/work/pyOCD/dist/flash_tool
10979 INFO: Building EXE from EXE-00.toc completed successfully.
flit commented 4 years ago

Take a look at my feature/binary_build branch. There is a scripts/pyocd.spec file and scripts/build_pyinstaller.sh. Unfortunately, it doesn't work yet due to an issue with the prettytable dependency. It builds ok, but when you run pyocd a pkg_resources.DistributionNotFound exception is raised when prettytable tries to call pkg_resources.get_distribution(). There is an attempt at a hook under scripts/hooks based on pyinstaller/pyinstaller#4809, but it doesn't work.

If you can make progress, that would by great! You can either comment here with your improvements or create a PR to my feature/binary_build branch.

Note that another option I haven't yet explored but seems promising is PyOxidizer.

Littermonkey commented 4 years ago

I found the root cause that package (Prettytable) init.py is an issue. and I just added some codes in that file like this : from pkg_resources import get_distribution, DistributionNotFound import os.path try: _dist = get_distribution('prettytable') dist_loc = os.path.normcase(_dist.location) here = os.path.normcase(file) if not here.startswith(os.path.join(dist_loc, 'prettytable')): raise DistributionNotFound except DistributionNotFound: version = 'Please install this project with setup.py' else: version = _dist.version

Littermonkey commented 4 years ago

Despair is that when I execute "./pyocd list --target" explore some warnnings, so I'm not sure if it's still a build binary issue. ./dist/pyocd list --target 0000215:WARNING:loader:unable to open builtin SVD file: [Errno 2] No such file or directory: '/tmp/_MEIp1l1zs/pyocd/debug/svd/svd_data.zip' Traceback (most recent call last): File "pyocd/debug/svd/loader.py", line 37, in from_builtin zip_stream = pkg_resources.resource_stream("pyocd", BUILTIN_SVD_DATA_PATH) File "pkg_resources/__init__.py", line 1135, in resource_stream File "pkg_resources/__init__.py", line 1383, in get_resource_stream File "pkg_resources/__init__.py", line 1386, in get_resource_string File "pkg_resources/__init__.py", line 1553, in _get File "/home/glb/build_pyocd/env/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 341, in get_data with open(path, 'rb') as fp: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEIp1l1zs/pyocd/debug/svd/svd_data.zip'