I am attempting to use Nuitka to create a standalone executable from this basic Kivy example hello.py:
from kivy.app import App
from kivy.uix.button import Button
class TestApp(App):
def build(self):
return Button(text='Hello World')
TestApp().run()
When I do python -m nuitka --follow-imports hello.py, Nuitka creates the executable, but when I run this, it fails with
../dist-packages/kivy/event.py", line 8, in import kivy._event No module named _event
The module _event is in fact the c extension module _event.so which Python interpreter finds and loads OK.
My question is - what causes this error? Can I get around this?
It appears that Nuitka can deal with c extension modules generally, e.g. doing python -m nuitka --follow-imports on
from bluetooth import bluez as _btz
print _btz._bt
print "Hello World!"
results in a functioning executable even though module bluez has an import _bluetooth statement referring to a _bluetooth.so extension module:
./hello.bin
<module 'bluetooth._bluetooth' from
'/usr/lib/python2.7/dist-packages/bluetooth/_bluetooth.so'>
Hello World!
In case it is relevant: system is MX Linux 18.3 (Debian Stretch based), Python 2.7.13, Kivy v1.10.1, Nuitka 0.6.8.4
My objective is to speed up Kivy application startup time, as opposed to packaging the application for distribution. For example, I have a RPI2B embedded system running a Kivy app on Buildroot generated Linux. This cold boots in 12 seconds, of which 6 seconds is Kivy app startup time. So for example PyInstaller does not help me here, whilst Nuitka potentially could.
UPDATE
I gave up trying to get this to work with Python 2.7 not sure what happened but I ran into some Nuitka infinite optimisation loop problem. Got a bit further with Python 3.5, these are my notes from when I did it:
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install python3-setuptools
sudo apt-get install python3-dev
sudo apt-get install mesa-common-dev
sudo apt install libgl1-mesa-dev
sudo apt-get install chrpath
pip3 install wheel
pip3 install pygame
pip3 install kivy (ended up with 1.11.1)
pip3 install nuitka
followed clues from here
https://github.com/kivy/kivy/wiki/Packaging-Kivy-apps-written-in-Python-3,-targeting-Windows-using-Nuitka
Create dependencies.py:
# external modules
import kivy.cache
import kivy.atlas
import kivy.network
import kivy.network.urlrequest
#import kivy.lib.osc
#import kivy.lib.osc.OSC
#import kivy.lib.osc.oscAPI
import kivy.lib.mtdev
#import kivy.lib.sdl2
import kivy.factory_registers
import kivy.input.recorder
import kivy.input.providers
import kivy.input.providers.tuio
import kivy.input.providers.mouse
#import kivy.input.providers.wm_common
#import kivy.input.providers.wm_touch
#import kivy.input.providers.wm_pen
import kivy.input.providers.hidinput
import kivy.input.providers.linuxwacom
#import kivy.input.providers.mactouch
import kivy.input.providers.mtdev
# compiled modules
import kivy.event
import kivy.graphics.buffer
#import kivy.graphics.c_opengl_debug
import kivy.graphics.compiler
import kivy.graphics.context_instructions
import kivy.graphics.fbo
import kivy.graphics.instructions
import kivy.graphics.opengl
import kivy.graphics.opengl_utils
import kivy.graphics.shader
#import kivy.graphics.stenctil_instructions
import kivy.graphics.texture
import kivy.graphics.transformation
import kivy.graphics.vbo
import kivy.graphics.vertex
import kivy.graphics.vertex_instructions
import kivy.graphics.tesselator
import kivy.graphics.svg
import kivy.properties
import kivy.graphics.cgl_backend
# core
# import kivy.core.audio.audio_gstplayer
# import kivy.core.audio.audio_pygst
import kivy.core.audio.audio_sdl2
# import kivy.core.audio.audio_pygame
# import kivy.core.camera.camera_avfoundation
# import kivy.core.camera.camera_pygst
# import kivy.core.camera.camera_opencv
# import kivy.core.camera.camera_videocapture
import kivy.core.clipboard.clipboard_sdl2
# import kivy.core.clipboard.clipboard_android
# import kivy.core.clipboard.clipboard_pygame
# import kivy.core.clipboard.clipboard_dummy
# import kivy.core.image.img_imageio
# import kivy.core.image.img_tex
# import kivy.core.image.img_dds
import kivy.core.image.img_sdl2
# import kivy.core.image.img_pygame
# import kivy.core.image.img_pil
# import kivy.core.image.img_gif
# import kivy.core.spelling.spelling_enchant
# import kivy.core.spelling.spelling_osxappkit
import kivy.core.text.text_sdl2
# import kivy.core.text.text_pygame
# import kivy.core.text.text_sdlttf
# import kivy.core.text.text_pil
# import kivy.core.video.video_gstplayer
# import kivy.core.video.video_pygst
# import kivy.core.video.video_ffmpeg
# import kivy.core.video.video_pyglet
# import kivy.core.video.video_null
import kivy.core.window.window_info
import kivy.graphics.cgl_backend.cgl_glew
import kivy.graphics.cgl_backend.cgl_gl
import kivy.graphics.cgl_backend.cgl_sdl2
import kivy.core.window.window_sdl2
#import kivy.core.window.window_egl_rpi
# import kivy.core.window.window_pygame
# import kivy.core.window.window_sdl
# import kivy.core.window.window_x11
Use it like this:
python3 -m nuitka --include-plugin-files=dependencies.py --standalone hello.py
cp -r <path/to>/lib/python3.5/site-packages/kivy/data <path/to>/hello.dist/kivy/
./hello.dist/hello
Any "ImportError: No module named <...>" is remedied by adding a corresponding import statement in dependencies.py
However resulting executable appears to be no faster than original python script. And it wouldn't run under a separate MX Linux instance on the same machine, I got this:
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 155 (GLX)
Minor opcode of failed request: 3 (X_GLXCreateContext)
Value in failed request: 0x0
Serial number of failed request: 72
Current serial number in output stream: 73
Related
I have an scheduled crontab to run every minute that calls a shell script that runs the python script. My problem is that I get an ModuleNotFoundError. I'm a newbie in terms of cronjobs and Linux
crontab
* * * * * sh /home/pablo_racana/queries/test.sh >> out.txt 2>&1
sh
#!/bin/sh
cd "$(dirname "$0")";
CWD="$(pwd)"
echo $CWD
PYTHONPATH=/home/pablo_racana/.local/lib/python3.7/site-packages/
HOME=/home/pablo_racana
python3 test_cron.py
python script
import datetime
import sys
import pyodbc
import json
import struct
import adal
import time
import pandas as pd
import numpy as np
import os
For each iteration I receive the following error
Traceback (most recent call last):
File "test_cron.py", line 6, in <module>
import adal
ModuleNotFoundError: No module named 'adal'
I saw in a different answer that I needed to add the PYTHONPATH to where my package is installed, but in my case, I have packages instaled in different folders
import pyodbc
print(pyodbc)
/home/pablo_racana/.local/lib/python3.7/site-packages/
import adal
print(adal)
/opt/conda/lib/python3.7/site-packages/
solved.
I added the following script with the filepaths
import sys
sys.path.append(r'/home/pablo_racana/.local/lib/python3.7/site-packages/')
sys.path.append(r'/opt/conda/lib/python3.7/site-packages/')
I do not program on Python, so I don't know what the problem is.
I just can't start the program from the command line, this is displayed:
Here is code __init__.py
import os
import sys
from PyQt4 import QtGui, QtCore
from pynfb.experiment import Experiment
from pynfb.io.xml_ import xml_file_to_params
from pynfb.settings_widget.general import GeneralSettingsWidget
from pynfb.settings_widget.inlet import InletSettingsWidget
from pynfb.settings_widget.protocol_sequence import ProtocolSequenceSettingsWidget
from pynfb.settings_widget.protocols import ProtocolsSettingsWidget, FileSelectorLine
from pynfb.settings_widget.signals import SignalsSettingsWidget
from pynfb.settings_widget.composite_signals import CompositeSignalsSettingsWidget
from pynfb.settings_widget.protocols_group import ProtocolGroupsSettingsWidget
static_path = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '/static')
class SettingsWidget(QtGui.QWidget):
You need to install PyQt4 first: https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyqt4.
Download the correct file corresponding to the version of your python, e.g. PyQt4‑4.11.4‑cp37‑cp37m‑win_amd64.whl then install by using pip (https://pip.pypa.io/en/stable/installing/)
pip install PyQt4-4.11.4-cp37-none-win_amd64.whl
I am trying to run the chatbot on windows 10. Python version I am using is Python 3.6.6. I installed rasa-core using pip3 install rasa_core and the installation was completed.
But every time I run my code, I get ImportError: No module named rasa_core.policies.keras_policy.
here are the import libraries:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import argparse
import logging
import warnings
import csv
import pandas as pd
import unicodedata
from rasa_core.policies.keras_policy import KerasPolicy
from rasa_core import utils
from rasa_core.actions import Action
from rasa_core.actions.forms import FormAction
from rasa_core.agent import Agent
from rasa_core.channels.console import ConsoleInputChannel
from rasa_core.events import SlotSet
from rasa_core.events import AllSlotsReset
from rasa_core.featurizers import (
MaxHistoryTrackerFeaturizer,
BinarySingleStateFeaturizer)
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.policies.memoization import MemoizationPolicy
from rasa_nlu.model import Metadata, Interpreter
How can I get rid of Import Errors related to rasa-core?
What version of rasa-core are you using?
For e.g. on my mac Below are versions.
pip freeze |grep -i rasa
rasa-core==0.8.2
rasa-core-sdk==0.11.4
rasa-nlu==0.11.4
for rasa-core==0.8.2 class KerasPolicy is in
python3.6/site-packages/rasa_core/policies/keras_policy.py.
Hence you would import it using,
from rasa_core.policies.keras_policy import KerasPolicy
However, if you are using latest version rasa-core. for e.g.
pip freeze |grep -i rasa
rasa-core==0.12.0a3
rasa-core-sdk==0.11.4
rasa-nlu==0.13.3
Then class KerasPolicy is in
/python3.6/site-packages/rasa_core/policies/keras_policy.py .
Hence you would import it using
from rasa_core.policies.keras_policy import KerasPolicy
It appears that you are using an older version of rasa-core and trying newer versions based example.
You need to upgrade both rasa-core and rasa-nlu.
Here's link to latest requirement.txt that you can download.
After that simply run following to get dependencies installed along-with rasa-core and rasa-nlu.
pip install -r requirement.txt
i am going crazy with an import problem. It should be 'simple' because i have a script (test2.py) with this import inside:
from jinja2 import Environment, FileSystemLoader, PackageLoader,select_autoescape
def myfun(arg1)
...
env = Environment(loader=FileSystemLoader('/var/www/html/templates'),autoescape=select_autoescape(['html', 'xml']))
...
Note that this script test2.py is called by test1.py (called by a CGI scripr) like that :
import test2
test2.myfun(arg1)
then i get the error:
from jinja2 import Environment, FileSystemLoader, PackageLoader, select_autoescape
ImportError: cannot import name 'select_autoescape'
the crazy thing is that if i call (directly) another script with these imports:
from jinja2 import Environment, FileSystemLoader, PackageLoader,select_autoescape
it goes fine! it does import the select_autoescape thing ...
So my question is why does it not import it when i call it from another function/module?
Try reinstalling jinja2:
sudo pip3 install --upgrade jinja2
It worked for me.
I have a python script that i have to import all these modules, which some of them require downloading:
import datetime
from dateutil import parser
from tkinter import filedialog
import tkinter
import mailbox
import pprint
import json
import urllib.request
from tkinter import *
Is there a way, using py2exe, i can convert the script into a windows executable. If so, how?
To simplify the procedure, you will want to have all your modules already downloaded. This can be accomplished with a simple "pip install " from command prompt. Then it is as simple as writing and running a setup.py file - detailed directions for how to do this can be found here.