cx_freeze ignores custom variables module - matplotlib

I'm trying to freeze a small GUI I made using PyQT5, Matplolib and Python 3.3.
I'm a beginner so please pardon my ignorance.
The program has:
- one QMainWindow
- two auxiliary QDialogs with Matplotlib plots
- one Variables_Module that I use to store variables (rather than using global)
- one custom Class called ROI
When running from Python terminal the code works fine.
Issue: When running the exe obtained with cx_freeze QMainWindow is loaded, user chooses data and data is immediately shown in first QDialog. Second QDialog uses variables stored in the "Variables_Module" and should show a matplotlib hist2d but nothing appears.
For this reason I think Variables_Modules does not get included in the build somehow.
the Main.py has these includes:
import sys, time
from PyQt5.QtCore import Qt, pyqtSignal, QObject
from PyQt5.QtWidgets import QWidget, QApplication, QMainWindow, QFormLayout, QVBoxLayout,QFileDialog, QDialog, QPushButton, QGridLayout, QMessageBox, QSlider, QSpinBox, QGroupBox, QLabel, QCheckBox, QComboBox, QColorDialog, QProgressDialog
from HySP_main_GUI import Ui_Main
import numpy
from matplotlib.pylab import *
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.figure import Figure
import matplotlib.pyplot as pyplot
#these are the "custom" modules
import Variables_Module
from ROI import Resizable_animated_rect
from scipy import ndimage
I tried including the "custom" modules in the setup.py in every combination as Includes or includefiles or packages with no solution.
I do understand I'm not supposed to put these modules everywhere but I'm out of ideas.
Also, all files (Main.py, ROI.py, Variables_Module.py) are in the same folder and no errors are given when running cx_freeze build.
The setup.py I'm using is:
import sys
from cx_Freeze import setup, Executable
includes = ["ROI","Variables_Module"]
includefiles = ['ROI.py','Variables_Module.py']
excludes = [ 'Tkinter']
packages = ["ROI","Variables_Module"]
path = []
# Dependencies are automatically detected, but it might need fine tuning.
build_exe_options = {
"includes": includes,
"include_files": includefiles,
"excludes": excludes,
"packages": packages,
"path": path
}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
exe = None
if sys.platform == "win32":
exe = Executable(
script="E:\\Python\\Projects\\test\\test.py",
initScript = None,
base="Win32GUI",
compress = True,
copyDependentFiles = True,
appendScriptToExe = False,
appendScriptToLibrary = False,
icon = None
)
setup(
name = "test",
version = "0.1",
author = 'test',
description = "My GUI!",
options = {"build_exe": build_exe_options},
executables = [exe]
)

It would appear that warnings halt the frozen exe.
Before plotting my new image some warnings regarding NaN were shown and apparently were preventing the app from going on with calculations.
I solved suppressing the warning in the troublesome function using:
import warnings
warnings.simplefilter("ignore")
this solves the problem. Took 2 days. -_-'

Related

error:can't import name 'Protocal' from 'typing'

when i run import ptwtin colab,an error discribed in title occurs,but as I run
from typing_extensions import Protocol,it runs correctly.So how to import ptwt in colab?

cx_freeze and PyQt5 build error when building the project

I'm having issues getting cx_freeze to build my program, so I started afresh and discovered the issue was with PyQt5. I stripped down the code to this
import os
import sys
from PyQt5 import QtWidgets
print("program ran!")
The setup.py looks like this:
from setuptools import find_packages
from cx_Freeze import setup, Executable
options = {
'build_exe': {
'includes': [
],
'packages': [
'PyQt5.QtCore', 'PyQt5.QtGui', 'PyQt5.QtWidgets'
],
'excludes': [
]
}
}
executables = [
Executable('test2.py',
base=None,
targetName='program.exe')
]
setup(
name='program',
packages=find_packages(),
version='0.1',
description='PCPRo 2022',
executables=executables,
options=options
)
I build the program using the command python setup.py build
When I run the resulting .exe I get the error:
Fatal Python error: _PyInterpreterState_Get(): no current thread state
Python runtime state: unknown
If I remove the line from PyQt5 import QtWidgets and rebuild, the program runs as expected.
I am using Python 3.7.4 [MSC v.1916 64 bit (AMD64)] on win32

Module not found: Error: Can't resolve 'react-native/Libraries/Image/resolveAssetSource'

I'm adding an audio module in my current react-native project. I have tried installing several modules (react-native-sound, react-native-track-player). Getting in both modules the same Error output, which is always pointing in the 'react-native/Libraries/Image/resolveAssetsource' as module not found.
ERROR in ./node_modules/react-native-track-player/lib/index.js
Module not found: Error: Can't resolve 'react-native/Libraries/Image/resolveAssetsource' in 'D:\workspaces\web\react\blink\node_modules\react-native-track-player\lib'
# ./node_modules/react-native-track-player/lib/index.js 1:401-459
# ./node_modules/react-native-track-player/index.js
# ./components/ui/BlinkAudio/BlinkAudio.web.js
# ./components/ui/BlinkAudio/index.web.js
# ./components/dialogs/ResourceDetails/ResourceDetails.js
# ./components/dialogs/ResourceDetails/index.js
# ./components/panels/catalog/CatalogPanel.js
# ./components/parts/Main/Main.js
# ./components/parts/Main/index.js
# ./index.web.js
This is the current imports in the index file of the audio module react-native-track-player:
import { Platform, AppRegistry, DeviceEventEmitter, NativeEventEmitter, NativeModules } from 'react-native';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetsource';
I have tried to fix this including 'resolveAssetsource' from the imports of 'react-native' as below:
import {
Platform,
AppRegistry,
DeviceEventEmitter,
NativeEventEmitter,
NativeModules,
resolveAssetsource
} from 'react-native';
But I am not pretty sure if it would be the best way and normally I don't like to touch package node-modules directly.
I also tried to exclude the audio module from webpack loaders with no result.
module: {
loaders: [
{
test: /\.js?$/,
exclude: function (modulePath) {
return (
/node_modules/.test(modulePath) &&
!/node_modules(\\|\/)react-native-track-player/.test(modulePath)
);
},
I wonder if someone could help me to find an answer and if is possible to deal with this react-native issue, as I'm thinking that these audio modules are calling wrongly the resolveAssetsource, or in the other hand, react-native doesn't provide this specific Library for third parties, I don't know.
This seems to be a syntax error issue. There is no file nor module named resolveAssetsource, the module and filename is resolveAssetSource with a capital S.
Try to remove react-native-track-player with yarn remove react-native-track-player and install it again (or delete the entire node_modules directory and run yarn install again) as the source code under react-native-track-player/lib/index.js has it properly without any errors:
import { Platform, AppRegistry, DeviceEventEmitter, NativeEventEmitter, NativeModules } from 'react-native';
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
If you use it elsewhere, you'll have to import it like this:
import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';
But that is not the prefered way to do it, as this method is a member of the RN Image class/component Image.resolveAssetSource(source), so, it's better to just import the Image component and use it like this:
import {
Platform,
AppRegistry,
DeviceEventEmitter,
NativeEventEmitter,
NativeModules,
Image // Add Image import
} from 'react-native';
// and use the function as of Image method
let audioAssetSource = Image.resolveAssetSource(audioSource);
Either way, you'll have the method working and resolve the asset source information.

How can a README.md file be included in a PyPI module package using setup.py?

I want to include a README.md file with my module package for PyPI such that it can be read by a function in my setup.py. However, it is not obvious to me how to get setup.py and related infrastructure to actually include the README.md file.
I have included a MANIFEST.in file in my package that itself lists README.md and I have set the setuptools.setup argument include_package_data to True but this has not worked.
manifest.in:
junkmodule.py
junkmodule_script.py
LICENSE
MANIFEST.in
README.md
setup.py
setup.py:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import pypandoc
import setuptools
def main():
setuptools.setup(
name = "junkmodule",
version = "2017.01.13.1416",
description = "junk testing module",
long_description = pypandoc.convert("README.md", "rst"),
url = "https://github.com/user/junkmodule",
author = "LRH",
author_email = "lhr#psern.ch",
license = "GPLv3",
include_package_data = True,
py_modules = [
"junkmodule"
],
install_requires = [
"numpy"
],
scripts = [
"junkmodule_script.py"
],
entry_points = """
[console_scripts]
junkmodule = junkmodule:junkmodule
"""
)
if __name__ == "__main__":
main()
The commands I use to register and upload the module to PyPI are as follows:
python setup.py register -r https://pypi.python.org/pypi
python setup.py sdist upload -r https://pypi.python.org/pypi
I'm using this in my modules, try:
import pypandoc
try:
description=pypandoc.convert('README.md', 'rst')
except (IOError, ImportError):
description=open('README.md').read()

Jar files required to access Selenium class functions

Currently I have included the following JAR files to playback selenium recordings using JAVA.
junit-4.10.jar
selenium-java-2.24.1.jar
selenium-server-standalone-2.24.1.jar
Also I have imported these packages
import com.thoughtworks.selenium.Selenium;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
But with just these, I am not able to access selenium class functions like getAlert() or getConfirmation().
So are there any library files or JAR files that I have missed out on?
You can download the Java Client driver package 2.25.0 from the Selenium HQ site and then add all the jars in your project's referenced libraries.
You didn't imported the DefaultSelenium class which is in com.thoughtworks.selenium package so add this line to your code and it will work.
import com.thoughtworks.selenium.DefaultSelenium;