I'm using python 3.5.1 64 bit.
My operating system is Windows 10.
I installed: pip install PyQt4-4.11.4cp35-none-win_64.whl from gohlke site.
pip says it was installed successfully.
I can import PyQt4 but none of the modules in it.
It is installed in site-packages.
When I open the PyQt folder I find: QtCore.pyd and QtCore.dll, but when I try to import them I get a message that they aren't found. The program is from Summerfield's book. Here it is:
import sys
import time
import PyQt4
from PyQt4.QtCore import *
from PyQt4.QtGui import *
app = QApplication(sys.argv)
try:
due = QTime.currentTime()
message = "Alert!"
if len(sys.argv) < 2:
raise ValueError
hours, mins = sys.argv[1].split(":")
due = QTime(int(hours), int(mins))
if not due.isValid():
raise ValueError
if len(sys.argv) > 2:
message = " ".join(sys.argv[2:])
except ValueError:
message = "Usage: alert.pyw HH:MM [optional message]" #24hr clock
while QTime.currentTime() < due:
time.sleep(20)
label = QLabel("<font color=red size=72><b>" + message + "</b></font>")
label.setWindowFlags(Qt.SplashScreen)
label.show()
QTimer.singleShot(60000, app.quit)
app.exec()
I solved this problem. I didn't have msvcp140. Install Visual C++ Redistributable for Visual Studio 2015 and propably will be fine. I also changed PyCharm version to 4.5.4
Related
Unfortunately, I always get this error message with Frappe, so I ask you that you can maybe help me and give me a few types. Thank you and I'll be happy to wait for your answer. Thanks
Error:
Exception has occurred: ModuleNotFoundError
No module named 'frappe'
File "/home/erp/frappe-bench/apps/erpnextfints/erpnextfints/erpnextfints/doctype/fints_import/fints_import.py", line 7, in
import frappe
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import now_datetime, get_datetime
Import "frappe.model.document" could not be resolvedPylancereportMissingImports***`
# -*- coding: utf-8 -*-
# Copyright (c) 2019, jHetzer and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import now_datetime, get_datetime
class FinTSImport(Document):
def validate_past(self, date, field_name):
if isinstance(date, str):
date = get_datetime(date).date()
if date >= now_datetime().date():
frappe.msgprint(
_("'{0}' needs to be in the past").format(field_name)
)
return False
if (now_datetime().date() - date).days >= 90:
frappe.msgprint(
_("'{0}' is more then 90 days in the past").format(field_name)
)
return False
return True
def before_save(self):
status = True
if self.from_date is not None:
status = self.validate_past(self.from_date, "From Date")
if self.to_date is not None:
from_date = get_datetime(self.from_date).date()
if from_date > get_datetime(self.to_date).date():
status = False
frappe.msgprint(_(
"'From Date' needs to be further in the past"
" then 'To Date'"))
if self.to_date is not None:
if not self.validate_past(self.to_date, "To Date"):
status = False
if not status:
frappe.throw(_("Validation of dates failed"))
def validate(self):
self.before_save()
Screenshot of VS Code:
Each Bench has it's own Python env which is where Frappe apps & their Python dependencies are installed. This directory can be found under the respective bench's root - /home/erp/frappe-bench in your case.
You have tell VS Code to use the Python interpreter from that environment. You can do that by either
Manually setting the interpreter for your session
You may follow the instructions mentioned in the docs or this YouTube video.
Changing your current working directory
Simply cd into your bench and open VS Ccode from there - cd /home/erp/frappe-bench && code . and VS Code detects the env folder automatically and uses it as the active interpreter.
I am learning to use PyQT5 and QtDesign. The workflow is :Click button->Change a image. But GUI failed to update until QMessege appeared. Here is a code. Firstly, I draw a button named pass_btn, a label named fds_img, by QtDesign.
Then, code as below:
from PyQt5 import QtWidgets, uic, QtGui
import os, sys
from PyQt5.QtWidgets import *
app = QtWidgets.QApplication(sys.argv)
dlg = uic.loadUi('grading_sys.ui')
stepper = 0
img_dir_list = [] #this is a image dir list
dlg.fds_img.setPixmap(QtGui.QPixmap(img_dir_list[stepper]))
def pass_btn():
global stepper
if stepper == len(img_dir_list) - 1:
QtWidgets.QMessageBox.information(None, 'Warning', 'Warning')
return
stepper += 1
dlg.fds_img.setPixmap(QtGui.QPixmap(img_dir_list[stepper]))
print('Try to refresh')
QApplication.processEvents()
dlg.pass_btn.clicked.connect(pass_btn)
dlg.show()
sys.exit(app.exec_())
So why I could not refresh the label? Or how could I refresh image when I click the button?
Finally, I solved this by using QTimer. I know it is a waste of CPU, may not efficient enough, but it finally works. But I still confusing about why it did't work before. I solved this as codes below:
First, put all the update codes in a def, then connected it with QTimer, and ran it every second:
def refresh_ui():
print('Try to refresh UI')
print('Prepare to change image' + str(img_dir_list[stepper]))
dlg.fds_img.setPixmap(QtGui.QPixmap(img_dir_list[stepper]))
timer = QTimer()
timer.timeout.connect(refresh_ui)
timer.start(1000)
My environment: MacOS 10.14.2, PyCharm 2018.3.3 edu edition, Python 3.6, PyQt5, QtDesign (through Anaconda). Dose this happened because of MacOS?
I created a python 3 application that has a tkinter GUI and selenium action upon clicking a button. Here is the setup.py file:
from cx_Freeze import setup, Executable
import sys
import os
from pathlib import Path
buildOptions = {"include_files":['execute.py'], "packages": ['encodings'], "includes": ['numpy.core._methods', 'numpy.lib.format'], "excludes": []}
if sys.platform=='win32':
base = "Win32GUI"
else:
base=None
executables = [
Executable('bot_gui.py', base=base)
]
home_path = str(Path.home())
user_txt_path = []
if sys.platform=='win32':
print("windows detected")
user_txt_path.append('\\user.txt')
else:
print("macos detected")
user_txt_path.append('/user.txt')
#for initialization
f = open(home_path + user_txt_path[0], "w+")
for i in range(12):
f.write("---\n")
setup(name='tachysloth',
version = '1.0',
description = 'test',
options = dict(build_exe = buildOptions),
executables = executables)
The problem is when I run python setup.py build, everything works fine; but when I run python setup.py bdist_mac, the GUI works when you click on the application (called tachysloth-1.0 below)
but when I click on a button to in the GUI to open google.com on Chrome, the button does not do anything.
If you need more information to assess this problem, please let me know and I will provide that information as soon as possible.
Thank you again.
I wrote the folowwing at the top of my script:
try:
from Tkinter import *
from Tkinter import messagebox
except ModuleNotFoundError:
from tkinter import *
from tkinter import messagebox
else:
print("tkinter error")
input()
sys.exit()
Running my script as .py or .pyw works without problems. But when I make and .exe out of it with cx_Freeze, the exe throws the error:
And why is that? how to solve this?
Thanks...
EDIT:
Also my setup.py:
import sys
import os
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r"C:\Python\Python36-32\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Python\Python36-32\tcl\tk8.6"
base = None
executables = [Executable("toolbar.py", base=base)]
packages = []
options = {
'build_exe': {
'packages':packages,
},
}
setup(
name = "Desktop Toolbar",
options = options,
version = "1.0",
description = " ",
executables = executables
)
Trying to compile a Python 3.3 application but running into problems after compiling it to win32 exe using cx_freeze on Windows 7.
Example:
Test.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import tkinter.messagebox
cl_parser = argparse.ArgumentParser(
description='Test app Command Line Parameters')
cl_parser.add_argument('--version', action='version', version='%(prog)s 1.0')
cl_parser.add_argument('-s', '--show', help='show simple message box',
action='store_true')
cl_args = cl_parser.parse_args()
if cl_args.show:
tkinter.messagebox.showinfo(title='Simple Message', message='Hi There')
Cx_Freeze Script
import sys
from cx_Freeze import setup, Executable
import shutil
#Remove Build/Dist Folder Before Compile
args = None
print('Removing Old Folders...')
try:
for args in sys.argv:
if args.find('build_exe') != -1:
shutil.rmtree('build', ignore_errors=True)
elif args.find('bdist_msi') != -1:
shutil.rmtree('dist', ignore_errors=True)
except:
pass
finally:
del args
print('Folders Removed')
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
options = {
'build_exe': {
'includes': 'atexit',
'include_msvcr': True
}
}
executables = [
Executable('Test.py', base=base, targetName='Test App.exe')
]
setup(name='Test App',
version='1.0',
description='Test App',
options=options,
executables=executables)
After the successful compile I try a few command line tests on the exe:
Test App.exe -s (This successfully shows the messagebox)
Test App.exe -h or TestApp.exe --version (Fails with AttributeError: 'NoneType' Object has no attribute 'write')
Is there a way that I can make it so that this will work? I am trying to create a PyQt4 application and don't want to have to compile this as a console application.
Your feedback would be appreciated
P.S. Yes I know i've included an example with tkinter but this is for demo purposes only.