Pyinstaller - app without needed library on macOS - python

I've prepared python script (using pycharm in both OS, projects with venv, pyinstaller cpmmand run in pycharm terminal) which begins with
'import pandas' and want to make macOS application.
In windows everything works fine after creating app with 'pyinstaller --onefile main.py' command.
In macOS, script works but app not. Tried
pyinstaller --onefile main.py and pyinstaller --onefile --hidden-import=pandas main.py but in both ways, app says:
"Traceback (most recent call last):
File "main.py", line 1, in
ModuleNotFoundError: No module named 'pandas'
[26064] Failed to execute script main
logout
"
Why pyinstaller makes my app without pandas? How to make it take pandas?
Thanks for all responses.

Related

How to make an executable file?

Code for the background image of the GUI :
bg = PhotoImage(file='images/all_button.png')
lbl_bg = Label(root, image=bg)
lbl_bg.place(x=0, y=0, relwidth=1, relheight=1)
Error
Traceback (most recent call last):
File "finalbilling.py", line 14, in <module>
File "tkinter\__init__.py", line 4061, in __init__
File "tkinter\__init__.py", line 4006, in __init__
_tkinter.TclError: couldn't open "images/all_button.png": no such file or directory
[7912] Failed to execute script finalbilling
There are many ways in which you can convert it into an executable program.
But one such easy way is to use pyinstaller.
Firstly, download a module named pyinstaller by entering the below code into your console:
pip install pyinstaller
Then, open the folder in which you have kept your program with console.
In windows, you can go to the folder and press shift key and right click to get the option to open with powershell.
In Mac, you can head to the folder > Right click on the folder > Click New Terminal at folder.
Then in the terminal you can either:
pyinstaller (name of your file).py
In this one you will get many other files associated with your executable program.
Don't try to delete those files else your executable file may get affected.
Instead, try the below one to get only one executable file.
pyinstaller --onefile (name of file).py
You can get the executable program into dist folder of the folder you opened into console.
And then you can convert it to zip and send others.
If you are getting any type of errors like:
No such file or directory [7912] Failed to execute script finalbilling
Then there might be an issue with your script or while opening or importing any file an error occurred.
As the same happened with me and after resolving the issue in script it worked.
So, try to resolve the issue in script and then try the above steps it will definitely work.
You can convert the python script to a standalone executable with all its dependencies included using different python packages. One such package is pyinstaller which can be used to create executable for Windows, Mac OS X, or GNU/Linux. pyinstaller
pip install pyinstaller
pyinstaller --onefile main.py
OR
pyinstaller --onefile -w main.py # (will not work for console app)
-w means not to open CMD

Can't launch file.app but can launch file.app/Contents/MacOS/file

I have an app on python+PyQt5, and I'm building it with Pyinstaller for MacOS by command:
pyinstaller --windowed main.py
It creates an "main.app" file in "district" directory, but when I'm trying to launch .app file (both from terminal and by mouseclicking) app crashes with error:
LSOpenURLsWithRole() failed for the application .../dist/main.app with error -10810.
When I'm launching main.app/Contents/MacOS/main -- everything is ok.
I have to mention, that my app uses some datafiles, which I put in dist/main.app/Contents/MacOS/ and /dist directories (just for test)

Creating Python Tkinter exe file with Pyinstaller problem

I have created GUI python2.7 program with Tkinter successfully without error. Now I want to make an executable file of it using pyinstaller in anaconda environment (I'm using windows 10).
Using this command
pyinstaller --onefile main.py I am able to create exe file successfully in dist folder. But when I tried to run the exe file, it showed error :
Traceback (most recent call last):
File "main.py", line 333, in <module>
File "main.py", line 90, in __init__
File "lib-tk\ttk.py", line 715, in current
_tkinter.TclError: Index 0 out of range
[22668] Failed to execute script main
Is the problem related to tkinter? I've tried the solution here : Problems with Pyinstaller with tkinter app on python 3.5 and here : How to make pyinstaller import the ttk theme? . But still same error
Try and do:
pyinstaller --onefile -w main.py
The -w flag stops python from bringing up the console, and so this could be why tkinter is failing.
Source:
This cool video
I highly recommend you watch this video as it also goes a little in depth on how to clean up after building the exe.
I used pyinstaller to create single exe file for a tkinter project, which contained several py files:
Main.py is my main python file which calls tkinter UI and I had several other python files imported to this Main.py.
Some libraries which I used include pandas,pyodbc
Open cmd in the same directory of the project; Use following command:
pyinstaller --noconfirm --onedir --windowed --icon=XYZ.ico "C:/Users/.../Tkinter_Project/Main.py"
Application was created with no dependencies. If there is any config or image files used, simply copy paste it to the 'dist' folder which gets created.

made a shell to run script on startup, suddently it gives me an importerror

I followed this guide: guide to create a startupfile which excecutes a python file on startup.
in step 2 it says I have to test the startupfile I just created and suddently my script says:
Traceback (most recent call last):
File "Display.py", line 1, in <module>
import pyowm
ImportError: No module named pyowm
the python file works perfect if I run it directly.
what I allready tried: run pip again to see if the lib was okay
check the /usr/local/lib/python3.4/dist-packages folder to see if it was there and it is.
I think this is a python issue and not a RaspberryPi issue thats why I uploaded it here.
runned by:
sh launcher.sh
inside is:
#!/bin/sh
# launcher.sh
# navigate to home directory, then to this directory, then execute python script, then back home
cd /
cd /home/pi/arduino/Python/Main/Master
sudo python Display.py
cd /
Simple fix: define the version of python which will be used. It used python 2.7. Yet the lib was for 3.4.

Basic Flask Issue w/ Importing

I'm following a Flask tutorial and am getting an import error. I have a file called run.py which contains:
from app import app
app.run(debug = True)
When I run ./run.py, I get:
Traceback (most recent call last):
File "./run.py", line 2, in <module>
from app import app
File "/Users/myName/Desktop/SquashScraper/app/__init__.py", line 1, in <module>
from flask import Flask
ImportError: cannot import name Flask
This seems similar to this issue: http://stackoverflow.com/questions/26960235/python3-cannot-import-name-flask
So I attempted the checked solution by running:
virtualenv -p /usr/bin/python3 my_py3_env
Unfortunately, I get:
The executable /usr/bin/python3 (from --python=/usr/bin/python3) does not exist
Any ideas what may be happening here?
Thanks for the help,
bclayman
If you want your virtual environment to be Python 3 but don't know the installation directory, use which python3. Use that directory in your virtualenv -p [directory] my_py3_env command to set up the Python 3 virtual environment.
I sounds like your pip is installing to your Python 2.X directory. If you're okay with that, you'll need to run the app either with python2 run.py, python2.X run.py where x is your installed version, or change the symlink of python in /usr/bin/python to your installation of Python 2.
This question has some more information.
Regardless of the version of Python that you wish to use, you will need to install Flask to that version of Python. See this question for that.

Categories