missing module aspose in file exe - python

I wrote a program which combines two or more PDFs in one and converts PDFs in Jpeg or PNG files.
I tried to create the .exe file but the "aspose" module was not found.
I used these command (I found a sample in this question with the same problem Problem using aspose-words after exe generation by auto-py-exe:
myDirectory CombinaPDF_004.py --onefile --collect-binaries "aspose" --collect-submodules "aspose"
What else could I do?

Example of how to create one-file bundled executable using PyInstaller (https://pyinstaller.org):
pyinstaller --noconfirm --onefile --console --collect-binaries "aspose" --collect-submodules "aspose" path/to/script
Its works fine for me.

'Digital.qubit' answer didn't work for me as it missed a step. My aspose modules being imported in my script are aspose.slides and aspose.pydrawing
The steps i took include:
Open command prompt
change directory to where your python script is located using the following command
cd path/to/script
Enter in the command
pyinstaller --noconsole --collect-binaries "aspose" --collect-submodules
"aspose.slides" script_name.py
To check if you need to include any submodules, check your imports in your script file, if your aspose import is it's own folder separate to aspose found in site packages (Mine is located here 'C:\Users\User\AppData\Roaming\Python\Python37\site-packages')
Then include it in the submodules quotations.
FOR EXAMPLE aspose.pydrawing is included in the aspose folder in site-packages so i didn't need to add it as a sub-module command as it is already included when pyinstaller collects the aspose-binaries through the '--collect-binaries "aspose"' command.
Hit enter on your command prompt to create the exe file.
After you have done this, navigate to your pythons site packages folder again usually located here ^
'C:\Users\User\AppData\Roaming\Python\Python37\site-packages'
and copy the aspose and aspose submodule folder, in my case it was "Apose.Slides-22.8.0.dist-info", into your 'dist/application_folder/' created when pyinstaller is finished. When it asks if you want to replace the files or skip, select Skip.
Launch the application and your ready to go.
Not sure if the op managed to get his working but hopefully this helps other people that have run into this issue

Related

pyinstaller to creating wrong 1 _MEIxxxx folder, but trying to open another

If this is happening to you, the error (In this case) is a broken installation of pyinstaller or python, remove it from the computer and do a fresh reinstallation.
When trying to create a exe with pyinstaller, it works fine and the bundled .dll file is included an it unpacks the _MEI folder with the necesarry files the correct places. BUT i creates one called _MEIxxx but tries to open a _MEIxxY which does not exist (yes, both changes name everytime it is launched)
I cannot see anywhere you can manually set the name of the _MEI folder which would make it much easier.
The cmd command i am running is:
pyinstaller script.py --add-data "PATH TO DLL\python39.dll;test" -F --runtime-tmpdir .
reproducible problem:
creating a fresh .py project with python 3.9(i use pycharm)
include code of:
print("HI")
then in cmd use:
pyinstaller main.py -F (we want it to be a onefile exe)
Then the .exe file is copied to another pc
Here we run it with CMD to see the error output.
It returns the error:
Error loading Python DLL: "path to local\Temp\_MEIXXXX\python39.dll
the error (In this case) is a broken installation of pyinstaller or python, remove it from the computer and do a fresh reinstallation.

PyInstaller - FileNotFoundError: [Errno 2] No such file or directory

I'm not too familiar with using PyInstaller but I have been trying to use it to convert my .py files to a single exe. I am using Windows 10 with Python 3.10.5 and PyInstaller 5.2. My files look like the following:
Scripts Folder
-venv Folder
-Dependent Files Folder
-main.py
-1.py
-2.py
-3.py
-4.py
I am able to create an exe using 'pyinstaller --onefile -w main.py' in the console and move it from dist to the main Scripts folder. Once I launch the exe I get the error FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\Jack\AppData\Local\Temp\_MEIXXXXX\palettable\colorbrewer\data\colorbrewer_all_schemes.json'. I've also tried using auto-py-to-exe and get the same issue.
When I check that directory I don't see a folder 'palettable' in the _MEIXXXXX folder (hence the error), but I'm not sure how to add it to that directory. I do see 'colorbrewer_all_schemes.json' in the venv folder within the same _MEIXXXXX folder but the exe can't find it there. I can't add it manually cause it is a temp folder and a new _MEIXXXXX folder will be generated each time I launch the exe again. I've also made sure the library 'palettable' is installed in the virtual environment and in console.
As I say I'm not too familiar with converting .py files to .exe so any help is appreciated. Let me know if you need more information.
I found an answer to my own question. I still don't know why it couldn't find the palettable library but I was able to get it working by putting this in the command window:
pyinstaller --collect-data palettable --onefile main.py
This allowed it to I guess collect it manually though I'm still not sure how it wasn't able to find palettable in the first place since its installed the same way as all the other dependent libraries. Hopefully this helps anyone with a similar issue.

How to convert tkinter script which uses multiple image resources to create a single executable

I want to create a single executable from my Python project which uses tkinter. A user should be able to download and run it without needing Python installed. What can I use to build a self-contained executable from a Python project?
my question is somewhat similar to this one but I didn't find what I was looking for there.
I have a folder which looks like this:
-project/
-script.py
-res/
-image1.jpg
-image2.jpg
-image3.jpg
In my script.py I am using the images from the res folder in my tkinter UI and I want to create an executable out of this script. what would be the best way to tackle this problem?
You can try using PyInstaller
PyInstaller - How to convert to .exe
1. Installation
The pyinstaller module makes you able to create a standalone exe file for pc from a python script, so that you can use it on other computers than do not have python or your python version.
To install pyinstaller: pip install
2. Create an exe
After you installed pyinstaller, go in the folder where your python script to be transformed in exe is and type in the command line (go in the address bar on top of the window and type cmd). Then type :
pyinstaller yourscript.py
where your script is the name of your file.
You will find a folder called “dist” where there is a folder called yourscript (if the name of your script was this) where there are many files and the exe file that will allow you to run the script also on other computer. You just have to copy the whole folder.
3. What to do if there are images
If you use images, that are in the same folder, for example, you can copy manually into the folder made by pyinstaller or you can run this command to make it do it for you:
pyinstaller –add-data “*.png;.” yourscript.py
This way you will see that in the folder where your exe is there are also the png files (all of them, if you want just one do not put the asterisc, but the whole name of the file.
External links - PyInstaller
Use a bundler like Pyinstaller.
Pyinstaller website
Include images in Pyinstaller
Note: If you are having issues with tkinter and pyinstaller take a look at this: Problems with Pyinstaller with tkinter app on python 3.5

How do I include poppler to pyinstaller generated exe when using pdf2image?

I made a simple script that converts pdfs inside the current directory to images. I want to make it into a standalone .exe file so that someone who doesn't have python installed on his PC can use it.
The problem is that pyinstaller fails to include poppler to the exe file so pdf2image does not run correctly and the built exe fails. Here's the error message:
pdf2image.exceptions.PDFInfoNotInstalledError: Unable to get page
count. Is poppler installed and in PATH? [32024] Failed to execute
script bulk_pdf2img
I'm currently working on conda environment that has pyinstaller and pdf2image and poppler installed from conda install command. It works just fine when I execute the python script from the prompt but when the script is converted to exe, it raises the above error.
I tried the following approaches:
1. Add --add-data option
I tried to add poppler data by doing this.
$ pyinstaller --onedir --add-data="C:/Users/myusername/anaconda3/pkgs/poppler-0.89.0-h20e2fe3_4/Library/include/poppler/*;./poppler" bulk_pdf2img.py
Doesn't work.
2. Add additional-hooks-dir option
I added projectdirectory/hooks/hook-pdf2image.py that has
from PyInstaller.utils.hooks import collect_all
data, binaries, hiddenimports = collect_all('pdf2image')
inside and ran
$ pyinstaller --onefile --additional-hooks-dir=hooks bulk_pdf2img.py
Also doesn't work.
I googled almost every Stackoverflow question that is apparently having the exact same problem as I am but couldn't find any valid solution. What should I do now?
From the docs
You will then have to add the bin/ folder to PATH or use poppler_path = r"C:\path\to\poppler-xx\bin" as an argument in convert_from_path.
Now, if you are using the --onefile option of pyinstaller it will unpack all the files into a temporary folder during the execution, you might want to look into this answer and the related post, to get the path right.
You can do any of the following
Execute this at the beginning to add the bin folder of poppler to PATH.
os.environ["PATH"]+=os.pathsep+os.path.join('path/to/poppler','bin')
pdf2image.convert_from_path('path/to/pdf',poppler_path=r"path\to\poppler\bin")

Windows- Pyinstaller Error "failed to execute script " When App Clicked

I am having a tough time overcoming this error, I have searched everywhere for that error message and nothing seems relevant to my situation:
"failed to execute script new-app"
new-app is my python GUI program. When I run pyinstaller using this command:
pyinstaller.exe --onedir --hidden-import FileDialog --windowed --noupx new-app.py
It does work smoothly. In addition, when I execute the command line to run the gui program, it works perfectly and the GUI is generated using this command:
.\dist\new-app\new-app.exe
But when I go to that file hopefully to be able to click the app to get the GUI, it gives me the error said above. Why is that?
I am using python2.7 and the OS is Windows 7 Enterprise.
Any inputs will be appreciated and thanks a lot in advance.
Well I guess I have found the solution for my own question, here is how I did it:
Eventhough I was being able to successfully run the program using normal python command as well as successfully run pyinstaller and be able to execute the app "new_app.exe" using the command line mentioned in the question which in both cases display the GUI with no problem at all. However, only when I click the application it won't allow to display the GUI and no error is generated.
So, What I did is I added an extra parameter --debug in the pyinstaller command and removing the --windowed parameter so that I can see what is actually happening when the app is clicked and I found out there was an error which made a lot of sense when I trace it, it basically complained that "some_image.jpg" no such file or directory.
The reason why it complains and didn't complain when I ran the script from the first place or even using the command line "./" is because the file image existed in the same path as the script located but when pyinstaller created "dist" directory which has the app product it makes a perfect sense that the image file is not there and so I basically moved it to that dist directory where the clickable app is there!
So The Simple answer is to place all the media files or folders which were used by code in the directory where exe file is there.
Second method is to add "--add-data <path to file/folder>"(this can be used multiple times to add different files) option in pyinstaller command this will automatically put the given file or folder into the exe folder.
In my case i have a main.py that have dependencies with other files. After I build that app with py installer using this command:
pyinstaller --onefile --windowed main.py
I got the main.exe inside dist folder. I double clicked on this file, and I raised the error mentioned above.
To fix this, I just copy the main.exe from dist directory to previous directory, which is the root directory of my main.py and the dependency files, and I got no error after run the main.exe.
Add this function at the beginning of your script :
import sys, os
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
Refer to your data files by calling the function resource_path(), like this:
resource_path('myimage.gif')
Then use this command:
pyinstaller --onefile --windowed --add-data todo.ico;. script.py
For more information visit this documentation page.
In case anyone doesn't get results from the other answers, I fixed a similar problem by:
adding --hidden-import flags as needed for any missing modules
cleaning up the associated folders and spec files:
rmdir /s /q dist
rmdir /s /q build
del /s /q my_service.spec
Running the commands for installation as Administrator
I was getting this error for a different reason than those listed here, and could not find the solution easily, so I figured I would post here.
Hopefully this is helpful to someone.
My issue was with referencing files in the program. It was not able to find the file listed, because when I was coding it I had the file I wanted to reference in the top level directory and just called
"my_file.png"
when I was calling the files.
pyinstaller did not like this, because even when I was running it from the same folder, it was expecting a full path:
"C:\Files\my_file.png"
Once I changed all of my paths, to the full version of their path, it fixed this issue.
I got the same error and figured out that i wrote my script using Anaconda but pyinstaller tries to pack script on pure python. So, modules not exist in pythons library folder cause this problem.
That error is due to missing of modules in pyinstaller. You can find the missing modules by running script in executable command line, i.e., by removing '-w' from the command. Once you created the command line executable file then in command line it will show the missing modules. By finding those missing modules you can add this to your command :
" --hidden-import = missingmodule "
I solved my problem through this.
I had a similar problem, this was due to the fact that I am using anaconda and not installing the dependencies in pip but in anaconda. What helped me was to install the dependencies in pip.
I found a similar issue but none of the answers up above helped. I found a solution to my problem activating the base environment. Trying once more what I was doing without base I got my GUI.exe executed.
As stated by #Shyrtle, given that once solved my initial problem I wanted to add a background image, I had to pass the entire path of the image even if the file.py and the image itself were in the same directory.
In my case (level noob) I forgot to install library "matplotlib". Program worked in Pycharm, but not when I tried open from terminal. After installed library in Main directory all was ok.

Categories

Resources