I tried to convert a python script called table.py to .exe
The scripts imports openpyxl, pandas, dataframe_image
I've tried using the modules in the title as so:
pyinstaller: I ran: pyinstaller --onefile -windowed table.py . When I click the executable there's a popup message saying Failed to execute script table
cx_Freeze: I ran python setup.py build_exe
it printed error: The baseline image directory does not exist. This is most likely because the test data is not installed. You may need to install matplotlib from the source to get the test data.
so I followed the answer here and ran:
pip install "numpy<1.18.3" "pillow<7"
python setup.py build_exe --excludes=matplotlib.tests,numpy.random._examples
and It poped up this message:
Anyone got any ideas on how to proceed now?
Related
To install a package that includes a setup.py file, usually you cd into the root directory where setup.py is located and then run the following:
python setup.py install
Now my problem is that I'm building an addon for another application, and while I can install "normal" package via code with the following:
subprocess.run([sys.executable, "-m", "pip", "install", package])
I also have to install a couple custom made packages, and if I try to do it like this:
subprocess.run([sys.executable, "-m", "/MSN-Point-Cloud-Completion-master/emd/setup.py", "install"])
I get the following error: Error while finding module specification for 'MSN-Point-Cloud-Completion-master/emd/setup.py' (ModuleNotFoundError: No module named 'MSN-Point-Cloud-Completion-master/emd/setup')
What is annoying me is that if I manually cd into the directory and simply run python setup.py install from the cmd it works just fine.
So the problem seems to be passing the relative path to the setup.py file, but as I said, considering this is an addon I need to install that setup.py from code. Any solution?
Reading comments made me realize a few mistakes.
First of all I realized that I shouldn't use -m flag in this case and this allow me to execute setup.py correctly. Also deleted the extra slash in the path and now the following works:
subprocess.run([sys.executable, "MSN-Point-Cloud-Completion-master/emd/setup.py", "install"])
However, since I wasn't in that directory still, I also got the following error c1xx: fatal error C1083: It is not possible to open file: 'emd_cuda.cu': No such file or directory and the compilation failed.
This definitely fixed all the problems:
import os
import subprocess
os.chdir("MSN-Point-Cloud-Completion-master/emd/")
subprocess.run([sys.executable, "setup.py", "install"])
So i'm packaging a python script with pyinstaller, and when I run the executable that is output in the dist folder, i see this error:
https://gyazo.com/729db46f4e7973b475b11c5a9810da19
Here is a screenshot of the error since the video goes fast:
https://gyazo.com/6f39ffd35561c3bc976aa9e52ee363f4
The line that the error refers to is this:
title = pyfiglet.figlet_format("Discord Tools")
How do I fix this?
Error message from running my exe:
ModuleNotFoundError: No module named 'openpyxl'
testHi.py
#simple test to see if openpyxl module works
import openpyxl
print ("hi")
input()
hook-openpyxl.py
# taken from pyinstaller dev team, store in same dir as testHi.py
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('openpyxl')
cmd line input:
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
I run the the hiTest and get the error above.
I have looked everywhere for this solution. Can anyone tell me what I am doing wrong.
I fixed my issue by installing it through Pip, rather than install the package through Pycharm, and Pyinstaller was able to find the package.
I got the idea from looking through the text in the command prompt and saw it was loading modules that I had installed via Pip and not through Pycharm.
I was able to get this working using auto-py-to-exe (which uses pyinstaller) by including the following folders/files from my python library into the same folder that I run pyinstaller from:
jdcal.py
openpyxl (folder)
et_xmlfile (folder)
pyinstaller command:
pyinstaller -y -F "[directory]/myscript.py"
Notes on Library Location:
Windows library location for me was: C:\users[username]\AppData\Local\Programs\Python\Python37-32\Lib
The packages were in the "site_packages" folder
use
--hiddenimport openpyxl
long with the previous solutions, it worked for me, I was able to enforce the import of openpyxl.
You was quite close. :-)
I fixed the problem by modifying the "hook-openpyxl.py" file. The command collect_data_files('openpyxl') actually returns an empty list. But there is another command collect_submodules which seems to do what we want. So my "hook-openpyxl.py" file looks like this.
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('openpyxl')
I placed the "hook-openpyxl.py" file in the same directory like my spec file. In the spec file I set to location of the new hook file
a = Analysis(
...
...
hookspath=['.'],
...
...
...
I guess, you will have the same result with your command line parameter
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
My environment
Python=3.8
openpyxl=3.0.10
PyInstaller=4.8
I want to compile my python code to binary by using pyinstaller, but the hidden import block me. For example, the following code import psutil and print the CPU count:
# example.py
import psutil
print psutil.cpu_count()
And I compile the code:
$ pyinstaller -F example.py --hidden-import=psutil
When I run the output under dist:
ImportError: cannot import name _psutil_linux
Then I tried:
$ pyinstaller -F example.py --hidden-import=_psutil_linux
Still the same error. I have read the pyinstall manual, but I still don't know how to use the hidden import. Is there a detailed example for this? Or at least a example to compile and run my example.py?
ENVs:
OS: Ubuntu 14.04
Python: 2.7.6
pyinstaller: 2.1
Hi hope you're still looking for an answer. Here is how I solved it:
add a file called hook-psutil.py
from PyInstaller.hooks.hookutils import (collect_data_files, collect_submodules)
datas = [('./venv/lib/python2.7/site-packages/psutil/_psutil_linux.so', 'psutil'),
('./venv/lib/python2.7/site-packages/psutil/_psutil_posix.so', 'psutil')]
hiddenimports = collect_submodules('psutil')
And then call pyinstaller --additional-hooks-dir=(the dir contain the above script) script.py
pyinstall is hard to configure, the cx_freeze maybe better, both support windows (you can download the exe directly) and linux. Provide the example.py, In windows, suppose you have install python in the default path (C:\\Python27):
$ python c:\\Python27\\Scripts\\cxfreeze example.py -s --target-dir some_path
the cxfreeze is a python script, you should run it with python, then the build files are under some_path (with a lot of xxx.pyd and xxx.dll).
In Linux, just run:
$ cxfreeze example.py -s --target-dir some_path
and also output a lot of files(xxx.so) under some_path.
The defect of cx_freeze is it would not wrap all libraries to target dir, this means you have to test your build under different environments. If any library missing, just copy them to target dir. A exception case is, for example, if your build your python under Centos 6, but when running under Centos 7, the missing of libc.so.6 will throw, you should compile your python both under Centos 7 and Centos 6.
What worked for me is as follows:
Install python-psutil: sudo apt-get install python-psutil. If you
have a previous installation of the psutil module from other
method, for example through source or easy_install, remove it first.
Run pyinstaller as you do, without the hidden-import option.
still facing the error
Implementation:
1.python program with modules like platform , os , shutil and psutil
when i run the script directly using python its working fine.
2.if i build a binary using pyinstaller. The binary is build successfully. But if i run the binary iam getting the No module named psutil found.I had tried several methods like adding the hidden import and other things. None is working. I trying it almost 2 to 3 days.
Error:
ModuleNotFoundError: No module named 'psutil'
Command used for the creating binary
pyinstaller --hidden-import=['_psutil_linux'] --onefile --clean serverHW.py
i tried --additional-hooks-dir= also not working. When i run the binary im getting module not found error.
I'm working with python 2.7 (32-bit) on Windows Vista. I downloaded some libraries including numpy, scipy, and pygame. When I try to import these modules the output says
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import numpy
ImportError: No module named numpy
I can find these modules in my python folders but for some reason it doesn't want to recognize it or some thing. (I made sure the file were compatible before downloading.)
Each package should contain a setup.py file. Run this with the command python setup.py install
For more information:
http://www.scipy.org/Installing_SciPy/Windows
http://pygame.org/install.html
"Everytime I run the command "python setup.py install" in the python shell it says SyntaxError: invalid syntax "
Please create a folder where you unzip the "numpy.zip" file, say the folder name is "c:\numpy"
Open a MS-DOS terminal (as described here : http://en.wikipedia.org/wiki/Command-line_interface), and type :
cd c:\numpy
python setup.py config
python setup.py install
This will set up the needed files in the correct folders for your python.
Enjoy !
To properly install this module:
In the Windows search bar (START MENU) type Command Prompt
Right-click on the Command Prompt icon (DO NOT go to cmd)
Click Run as Administrator
in the COMMAND PROMPT (DO NOT open cmd) type:
pip install numpy
This will install that module.
NOTE: If you are NOT in admin mode, you will get a message saying a fatal error has been raised.