Test code:
## file name: test.py
import scanpy as sc
print(sc.__version__)
Then install scanpy
using pip
pip install scanpy==1.8.2
pip install pyinstaller==4.7
I generated the exe file using the command line below:
python -m PyInstaller --noupx test.py
I then tried to run test.exe
. I got the error message:
Traceback (most recent call last):
File "scanpy\_metadata.py", line 28, in <module>
File "pathlib.py", line 1221, in read_text
File "pathlib.py", line 1208, in open
File "pathlib.py", line 1063, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\xie186\\PycharmProjects\\pitaya\\test_exe\\dist\\test\\pyproject.toml'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "scanpy\__init__.py", line 3, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
File "scanpy\_metadata.py", line 38, in <module>
File "scanpy\_compat.py", line 25, in pkg_metadata
File "importlib_metadata\__init__.py", line 984, in metadata
File "importlib_metadata\__init__.py", line 561, in from_name
importlib_metadata.PackageNotFoundError: No package metadata was found for scanpy
[20028] Failed to execute script 'test' due to unhandled exception!
But when I run this script in pycharm, it works fine. I checked the code related to this error: https://github.com/theislab/scanpy/blob/16e62d1336a95966238113cdb5ab50f7d9f880ce/scanpy/_metadata.py#L24
In pycharm, the try
part will fail and the code in except
part will be executed. But in the exe
file, it seems that the app will exit after the try
part fails.
Any help will be appreciated!
Adding --recursive-copy-metadata scanpy
solved my problem:
python -m PyInstaller --recursive-copy-metadata scanpy --noupx ..\test.py
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.