I'm using python 3.7 and I want to create an executable from a script that use "cairosvg" package, the exe gives me this error while trying to run it:
Traceback (most recent call last):
File "testCairo.py", line 1, in <module>
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "cairosvg\__init__.py", line 22, in <module>
File "pathlib.py", line 1199, in read_text
File "pathlib.py", line 1186, in open
File "pathlib.py", line 1039, in _opener
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\moham\\AppData\\Local\\Temp\\_MEI135122\\cairosvg\\VERSION'
[16072] Failed to execute script testCairo
any one has an idea how to solve this error ?
my code is only import cairosvg as the following:
import cairosvg
print('test')
Did you try to include the cairosvg folder in the pyinstaller command?
Pyinstaller --add-binary <path to cairosvg>;cairosvg testCairo.py
The package should be in your python installation folder, something like: "C:\Users<User>\AppData\Local\Programs\Python\Python37\Lib\site-packages\cairosvg".
The command should copy the cairosvg package folder from its location into your exe's dist folder. If you prefer one single file, you could also add "--onefile" to the pyinstaller command.
Related
I'm trying to make an executable with pyinstaller but it's giving an error in a library I'm using called aspose.words
this is the error that appears to me:
if the image does not open:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
KeyError: 'aspose.pydrawing'
The above exception was the direct cause of the following exception:
ImportError: Unable to import module dependencies. Cannot import the aspose.pydrawing module. The module not found or errors occurred while initializing it.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "main.py", line 3, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "Scripts\login.py", line 6, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "Scripts\principal.py", line 10, in <module>
File "aspose\__init__.py", line 48, in load_module
File "aspose\__init__.py", line 80, in _load_native_module
ImportError: One or more errors occurred while loading the module 'aspose.words' (-1009)
this is the command I used to create the executable:
pyinstaller --noconsole --onefile --collect-binar
ies "aspose" --collect-submodules "aspose" main.py --ico 3151580_game_maze_retro_icon.png
I saw a post here that needed to include aspose with the: --collect-binar command
ies "aspose" --collect-submodules "aspose". but the error continued
Try to use --collect-all option instead of --collect-binaries and --collect-submodules ones: such approach helped me.
i.e., try to use the following command:
pyinstaller --noconsole --onefile --collect-all "aspose" main.py --ico 3151580_game_maze_retro_icon.png
I am using sounddevice in my project running on Ubuntu - When I build a single file using pyinstaller it is failing with (The code works well when running the source python file):
Traceback (most recent call last):
File "Run_SD.py", line 2, in <module>
File "Smart_Device.py", line 26, in init Smart_Device
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "PyInstaller/loader/pyimod03_importers.py", line 540, in exec_module
File "sounddevice.py", line 71, in <module>
OSError: PortAudio library not found
[213] Failed to execute script Run_SD
Unfortunately I can't simply apt get install the required portaudio on the machine, so it needs to be included in the package. I have tried adding in the lib using:
--add-binary libportaudio.so:. --add-binary libportaudio.a:.
But this isn't working. I'm guessing I need to actually import the portaudio library into my python source - is that correct? Any pointers on how to do this?
I fixed this problem by editing:
versions/3.8.5/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-sounddevice.py
elif is_linux:
path = os.path.join(
sfp[0], "_sounddevice_data", "portaudio-binaries", "libportaudio.so"
)
versions/3.8.5/lib/python3.8/site-packages/sounddevice.py
elif _platform.system() == 'Linux':
_libname = 'libportaudio.so'
Then included the libportaudio.so in the pyinstaller build:
--add-binary _sounddevice_data/portaudio-binaries/libportaudio.so:./_sounddevice_data/portaudio-binaries/
I want to make a standalone exe with pyinstaller.
If I execute the .exe file I get the following Error:
C:\Users\User\Desktop\invpepeshort>.\invpepe.exe
Traceback (most recent call last):
File "invpepe.py", line 14, in <module>
import matplotlib.pyplot as plt
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod03_importers.py", line 531, in exec_module
File "matplotlib\__init__.py", line 820, in <module>
File "matplotlib\__init__.py", line 725, in _rc_params_in_file
File "contextlib.py", line 117, in __enter__
File "matplotlib\__init__.py", line 703, in _open_file_or_url
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\User\\AppData\\Local\\Temp\\_MEI142562\\matplotlib\\mpl-data\\matplotlibrc'
I hope someone can suggest a fix.
I don't know if it's the most correct answer, but I had the exact same problem as you.
For me solved, re-installing the Pyinstaller version develop
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
I have downloaded pyocd and built it successfully. Now I am able to run the tool from command line from any location. However when try to run it using pexpect it shows following error:
Traceback (most recent call last):
File "c:\Users\elephant\AppData\Local\Programs\Python\Python37-32\Scripts\pyocd-script.py", line 6, in <module>
from pkg_resources import load_entry_point
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 3086, in <module>
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 3070, in _call_aside
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 3099, in _initialize_master_working_set
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 574, in _build_master
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 892, in require
File "C:\Projects\runner\mytest\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\pkg_resources\__init__.py", line 778, in resolve
pkg_resources.DistributionNotFound: The 'pyocd==0.14.1.dev277+dirty' distribution was not found and is required by the application
Please help to understand what is wrong and why it works from command line?
The problem was that I tried to spawn pyocd.exe and pexpect was not able to find the package.
I changed the line to python -m pyocd and it just works fine.
I am new in Python and mistakenly thought that exe is compiled code as the other exe files in Windows. However, it is just an instruction to run the package using Python.
I created a python executable by using pyinstaller, but the jira module imported to my .py script is not present when I execute executable
Traceback (most recent call last):
File "myfile.py", line 7, in <module>
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
File "c:\users\rajivkum\appdata\local\continuum\anaconda3\lib\site-packages\Py
Installer\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "site-packages\jira\__init__.py", line 6, in <module>
File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
558, in get_distribution
File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
438, in get_provider
File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
959, in require
File "site-packages\setuptools-18.5-py3.5.egg\pkg_resources\__init__.py", line
846, in resolve
pkg_resources.DistributionNotFound: The 'jira' distribution was not found and is
required by the application
PyInstaller (and also cx_Freeze and Py2exe) have problems with including jira. What you have to do is to create, preferably in the same directory as your project a "hook file" for PyInstaller. Name the file
"hook-jira.py". Content of the file should look like that:
from PyInstaller.utils.hooks import copy_metadata
datas = copy_metadata('jira')
This will assure that PyInstaller will include jira. Then, you just have to run in the directory where myfile.py and hook file are located:
PyInstaller myfile.py --additional-hooks-dir=.
to tell PyInstaller that it should look for hook files in the current directory. This should solve the problem.