Can't import class and module on Python progrram - python

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

Related

"Failed to execute script" error while try run program from search

I created .exe file with PyInstaller. My program works without an error when i run it directly. But when i try to run it from file search it returns "Failed to execute script" error. It doesn't make sense, i do not understand it. Also i can't see any other error -whether console mode or not-
Used imports:
from PyQt5 import QtCore, QtGui, QtWidgets
from course_grabber import getCourseClasses,getCourseCodes
import random
from itertools import combinations
from profilim import Ui_Profilim
from dersler import Ui_dersPlaniPencere
from vt_islemleri import *
from threading import Thread
from webbrowser import open as tarayici_ac
import concurrent.futures
import datetime
import gc
import sys
import sqlite3 as sql
from course import Course
I found the solution. I tried a lot of things in code and pyinstaller. It's about permissions. When i run as administrator it worked. Program could not open external the database without administrator perm.

Nuitka and Kivy C extension module _event.so

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

Error: ModuleNotFoundError: No module named 'pyqtgraph'?

I keep struggling with importing the pyqtgraph module. It's really only about the import:
pip3 install pyqtgraph is not working.
My code:
from PyQt5 import QtGui
import PyQt5
import numpy as np
from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
import pyqtgraph as pg
import time
leaves:
<ipython-input-37-14dc06d126e4> in <module>
31 import numpy as np
32 from PyQt5.QtWidgets import QMainWindow, QApplication, QMessageBox
---> 33 import pyqtgraph as pg
34 import time
35 import sys
ModuleNotFoundError: No module named 'pyqtgraph'
I am guessing that your module gets installed to another Python version than what PYTHONPATH points to.
Try pip3 list -v | grep "pyqtgraph" on Unix-like OSs, or pip3 list -v | findstr "pyqtgraph" on Windows.
The directory location that will be shown will be different to your PYTHONPATH. Set your location to PYTHON3.7 dir and it should solve your problem. See here on how you can do that.

Spyder (Python 3.6) wkhtmltopdf ModuleNotFoundError: No module named 'main'

I'm a relatively inexperienced programmer and I ran these import statements last week on my computer without a problem but now this week when I run the following statements in particular the wkhtmltopdf import I run into an error.
import pyodbc
import pymysql
import numpy as np
import pandas as pd
import datetime
import jinja2
import wkhtmltopdf
from wkhtmltopdf.main import WKhtmlToPdf
import datetime
import calendar
from pathlib import Path
This leads to this error
enter image description here
Any help is appreciated

Import Error: Rasa Core

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

Categories

Resources