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")
I have a python package that involves several python modules. The project has been created in pycharm. I have used pyinstaller to create a single executable file of my python package. When I run the executable using a batch file I get an import error, specifically pandas has failed to be imported. Is there a reason why pyinstaller has not also collected the package dependencies in my virtual environment?
Thanks in advance for any help!
I have the following 2 errors:
(1) ModuleNotFoundError: No module named 'pandas._libs.tslibs.np_datetime'
(2) File "site-packages\pandas__init__.py", line 35, in
ImportError: C extension: No module named 'pandas._libs.tslibs.np_datetime' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
There is one pip script for each virtual environment. So when you install a python module it get installed into the projectname\venv\Lib\site-packages directory.
When you run pyinstaller from terminal to make the executable, pyinstaller checks for dependencies in Sys.path . But that path does not include the projectname\venv\Lib\site-packages directory. Therefore pyinstaller cannot find those particular dependencies. In such cases it gives you warnings.Those warning can be found in 'warnname.txt' near your executable file.
EDIT: How to Configure pycharm to run pyinstaller
First you need to add pyinstaller into project interpreter.
Then you need to setup running configurations.
Script name: path to your python script
working path: Project location
leave interpreter options as it is in the image.
Run pyinstaller. You can find your .exe in dist directory.
If the "Module not found" error still persists. You can add a hidden import hook and specify the names of the missing modules.Navigate to
Project Path\venv\Lib\site-packages\PyInstaller\hooks
and create a new "hook-pandas.py"(hook-modulename.py) script and make a list of hidden import modules like this.
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
And run pyinstaller again, and it should work now.
I have a Python project that I want to convert into an executable. I have installed Pyinstaller. I only know how to convert one single script into .exe, but I have multiple packages with multiple python scripts.
The command line I used with success is:
pyinstaller --noupx --onefile --add-data="cprofiles.ui;." cprofiles_lmfit.py
pyinstaller manages relatively well the multiple '.py' files that you import, no need to cite them. Under the 'add-data' option, you list the non-py files and in my example, the 'cprofiles_lmfit.py' file is the one containing the main.
But as indicated here need help to compile python with pyinstaller (and in few other posts), I am a beginner with pyinstaller. I was never able to use the 'theano' module and I did not optimize. I still have to test the suggestions in the answer.
Converting the main script into .exe should solve the problem, use -onefile to convert it to one exe and rest of the .py files should be included.
1) Open the command prompt
2) Install pyinstaller
Pip install pyinstaller
3) Test your python script first just to check python script should work with normal
.py extension. Saurabh is the name of python file
python saurabh.py
4) Convert the python into executable file
pyinstaller --onefile Saurabh.py
Notice we have passed “–onefile” as a argument which tell pyinstaller to create only one file
5) Go to directory and navigate to the dist folder.
Prerequisite : Install PyQt5 to avoid error.
pip install PyQt5
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.
Background: I have had success in the past installing and using Pyinstaller to transform my python projects into one-file executables. I don't think it is an issue with my source code or pyinstaller files.
Problem: I used a free, open-source library/module called easygui imported into my source code to build an application. The application works perfectly run natively or through the Python IDE. I am pretty sure the problem is that Pyinstaller is not finding the EasyGUI module to import (it automatically includes and compiles any libraries you import in the script).
Actions: My python folder is not in the C:\ drive, it is in the E:\ drive. I'm able to access the pyinstaller path in "E:\program files\python" but it is not reading the easygui library, I don't think. I installed pyinstaller and easygui using pip.
Reading a LOT of pyinstaller's documentation i tried to run it to include a paths dir like:
E:\Program Files Hard Disk\Python\Scripts>pyinstaller --paths
DIR "E:\Program Files Hard Disk\Python" --onefile "E:\Program Files\Python"
It does output the single executable in the build file but does not launch correctly. From what I can see in the console window the brief moment it's up, it looks like an easygui issue. Here is the result of attempting to launch the executable from the command-line:
Here is the compiling in the command window:
Please help