PyInstaller error "Python not installed as framework" - python

I am working on MacOS and I am trying to use PyInstaller to circulate a script to some non tech colleagues. The script is imaginatively called script_V1.py and runs fine.
Up to now, I have had issues with PANDAS and SCIPY but they seem to be resolved with with the command
pyinstaller --onefile --hidden-import pandas._libs.tslibs.timedeltas --hidden-import scipy._lib.messagestream script_V1.py
However, I am now getting a different error (I'll post the full error below)
RuntimeError: Python is not installed as a framework. The Mac OS X
backend will not be able to function correctly if Python is not
installed as a framework. See the Python documentation for more
information on installing Python as a framework on Mac OS X. Please
either reinstall Python as a framework, or try one of the other
backends. If you are using (Ana)Conda please install python.app and
replace the use of 'python' with 'pythonw'. See 'Working with
Matplotlib on OSX' in the Matplotlib FAQ for more information.
I have tried the solution in a similar question on Stack Exchange:
Installation Issue with matplotlib Python
But I think that is actually a different problem with import statements not working within the script itself. In my case if I run the script as a .py script it works fine. Anyway adding the suggested file did not alter the error message. Im new to this and seem to be really struggling with PyInstaller (more than with python itself) so any help much appreciated.
The full error message is (I've added line breaks for clarity)
Traceback (most recent call last):
File "script_V1.py", line 5, in <module>
import matplotlib.pyplot as plt
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/matplotlib/pyplot.py", line 115, in <module>
File "site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module
exec(bytecode, module.__dict__)
File "site-packages/matplotlib/backends/backend_macosx.py", line 17, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1191, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1161, in _load_backward_compatible
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module
module = loader.load_module(fullname)
RuntimeError: Python is not installed as a framework. The Mac OS X
backend will not be able to function correctly if Python is not
installed as a framework. See the Python documentation for more
information on installing Python as a framework on Mac OS X. Please
either reinstall Python as a framework, or try one of the other
backends. If you are using (Ana)Conda please install python.app and
replace the use of 'python' with 'pythonw'. See 'Working with
Matplotlib on OSX' in the Matplotlib FAQ for more information.
[2582] Failed to execute script script_V1
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
[Process completed]

So the way I got this to work in the end was to force Matplotlib to use WebAGG and also install the 'tornado' package (which is needed for some reason).

Related

Error when packaging eel project to an exe

I am building an python project with Eel, and I'm trying to package my program to an exe with PyInstaller as instructed in the documentation. However, I get the following error when I open the .exe:
Error
Traceback (most recent call last):
File "hello.py", line 1, in <module>
import eel
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "eel\__init__.py", line 8, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "bottle.py", line 73, in <module>
AttributeError: 'NoneType' object has no attribute 'write'
I tried to use auto py-to-exe instead of Pyinstaller, but I got the same error. Finally, I tried to package the Eello world example from the Eel documentation to see if it was my program that was the issue, but I still got the same error. I found a similiar problem in a github issue, but I fail to see what I should attach to --add-data.
I am running Python 3.10.8 and Eel 0.14.0. I've now tried python 3.8.9 and python 3.9.13 without luck.
Update
Upon further investigation, I discovered that the error only occours when I attach --noconsole at the end of my cmd python -m eel hello.py web --onefile --noconsole . However, I want my app to work without a visible console.
One of the libraries you are using is attempting to write to sys.stdout and sys.stderr, which are set to None when you run pyinstaller with --windowed option.
You need to explicitly set sys.stderr and sys.stdout in your programs code as early as possible to a writeable object like an open file or an io buffer.
for example:
import sys
outfile = open("logfile.txt", "wt")
sys.stderr = outfile
sys.stdout = outfile

python: problem with Sqlalchemy and Pyinstaller

I wrote a code with pyqt5 pandas sqlalchemy pyodbc libraries
but when I want to make an exe from my py file with pyinstaller I get this error:
in _load_hook_module
self._hook_module = importlib_load_source(
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\compat.py", line 632, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 529, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 1029, in load_module
File "<frozen importlib._bootstrap_external>", line 854, in load_module
File "<frozen importlib._bootstrap>", line 274, in _load_module_shim
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\username\AppData\Local\Programs\Python\Python39\lib\site-packages\PyInstaller\hooks\hook-sqlalchemy.py", line 32, in <module>
dialects = eval(dialects.strip())
File "<string>", line 0
SyntaxError: unexpected EOF while parsing
I searched for about 2 hours bet I couldn't find any solution
if you need to see my code comment on it and I will update the question with my code that I want to make exe of
I finally get it to work
I was exploring about my error till I found this:
this
and there was a guy that said:
if you install asyncio externally and you use above 3.3 python version then uninstall asyncio using pip uninstall asyncio it's works for me because 3.4 and above version added this in python-core so no need to add externally asyncio
and what I have done actually: pip uninstall asyncio
and it works like a charm!!!!
Thank you all
I faced the same issue when generating an executable with pyinstaller, simply run this line before invoking pyinstaller.
pip uninstall asyncio

Failed to execute script fbs_pyinstaller_hook

I'm trying to create an executable file from the my PyQt5 application. my system specs:
ubuntu 18.04
python (3.6.9)
fbs (0.8.9)
matplotlib (3.3.0)
numpy (1.19.1)
pandas (1.1.0)
I'm following fbs tutorial to build a executable file from my application. I run the application without error with fbs run command.
The fbs freeze command produce this output:
-c:12: MatplotlibDeprecationWarning:
The matplotlib.backends.backend_qt4agg backend was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
Done. You can now run `target/DataVisualization/DataVisualization`. If
that doesn't work, see https://build-system.fman.io/troubleshooting.
But I'm importing version 5 of matplotlib.backends.backend_qt4agg in my code as:
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
when I run the executable file from
~/MyProject/target/AppName
I get this error:
./AppName
Traceback (most recent call last):
File "fbs_pyinstaller_hook.py", line 2, in <module>
File "importlib/__init__.py", line 126, in import_module
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'fbs_runtime'
[1331] Failed to execute script fbs_pyinstaller_hook
I have checked the solutions given in these links, but none of them came handy!
The most common mistake
Failed to execute script fbs_pyinstaller_hook for pyqt5 gui application
Any ideas of what to do?
I entirely gave up using FBS.. pyinstaller works very well for compiling PyQt5 code.. try using just pyinstaller and see if that works.

Permission error importing custom functions in Python Anaconda3 Mac OS Catalina

Set-up
After updating to Catalina, Anaconda3 trouble commenced.
I've managed to solve most errors, doing a fresh install as advised by Anaconda, but can't seem to get around a permission error when trying to importing functions from other .py files – something that worked just fine before I upgraded to Catalina.
I run Python 3.7 from Spyder 3.3.6.
Error
Whenever I try to import a custom function, I get,
import os
os.chdir('/Users/mypath/payment_management')
from payment_knab import pay_knab
Traceback (most recent call last):
File "<ipython-input-1-cb99b6800e4e>", line 3, in <module>
from payment_knab import pay_knab
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 963, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 906, in _find_spec
File "<frozen importlib._bootstrap_external>", line 1280, in find_spec
File "<frozen importlib._bootstrap_external>", line 1249, in _get_spec
File "<frozen importlib._bootstrap_external>", line 1213, in _path_importer_cache
PermissionError: [Errno 1] Operation not permitted
Question
How do I run Anaconda/Spyder/Python with admin permission? Which command in terminal do I need to execute?
Stupidly enough I have actually managed to run with admin permission before via Terminal, but I forgot how...
I've been looking at StackOverflow for an hour now, but can't find anything that helps.
You've probably forgotten again how to do this. Use sudo spyder, dummy.

Logging module not working with Python3

I am having issues with the standard logging module. If I open a python2.7 shell and import logging everything works fine:
$ python
>>> import logging
>>>
But if I open a python3.4 shell and import logging I get the following error:
$ python3.4
>>> import logging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2222, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 2164, in _find_spec
File "<frozen importlib._bootstrap>", line 1940, in find_spec
File "<frozen importlib._bootstrap>", line 1916, in _get_spec
File "<frozen importlib._bootstrap>", line 1897, in _legacy_get_spec
File "<frozen importlib._bootstrap>", line 863, in spec_from_loader
File "<frozen importlib._bootstrap>", line 904, in spec_from_file_location
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/logging-0.4.9.6-py3.4.egg/logging/__init__.py", line 618
raise NotImplementedError, 'emit must be implemented '\
^
SyntaxError: invalid syntax
I have no idea what the problem is and can't seem to find anyone else who has had the same issue.
logging module is by default there in Python 3 environment .No need to import it.
You seem to have installed a third party library called logging in your Python 3 environment, which is hiding the standard library version, and one of its files has a typo.
I stupidly created a file called logging.py to try out some log features. Then when trying the code below, it is effectively referring to itself and can't find the debug method.
import logging
logging.debug("Debug message")
Changing my file name to logtest.py fixed the problem.
for me it was the previous install of a logging library under an older Python version.
pip3 uninstall logging
fixed it for me.

Categories

Resources