Why does my tkinter app will show a node.js window? - python

I use pyinstaller to pack a .py file.
Then when I use something about web crawler (I use requests module).
This window will show and disappear fastly.
I want to say that it is maybe incredible.It wouldn't pop this window when I run this .py file,but after using pyinstaller to pack it,it will pop this window.
(In another computer,it doesn't install node.js.And it doesn't pop this window)
Here is the module I use:
from pynput import keyboard
from PIL import Image, ImageTk
import ctypes
from io import BytesIO
import threading
from win10toast import ToastNotifier
import base64
from win32com.shell import shell
import requests
import execjs
import sys
import pythoncom
import getpass
import tkinter
from random import randint
from tkinter import ttk
from tkinter import messagebox
import os
import json
import traceback
from webbrowser import open_new_tab
from tkinter import scrolledtext
import win32con, win32clipboard, win32gui
from PIL.ImageGrab import grabclipboard, grab
from aip import AipOcr
import time
And the window is this:
What should I do except uninstall node.js? How to avoid this node.js window shows?
Thanks in advance.

Thanks bro,acw1668's suggestion enlighten me a lot.
I want to say,execjs module will run js code.
And if your computer install node.js and you set PATH for node.js,Then your default js environment is node.js(If you don't install node.js,then your default js environment is Jscript in windows system).
So if you doesn't want to use node.js,you should set the default js environment in python.
# change the js environment.
os.environ["EXECJS_RUNTIME"] = "JScript"
# all of environment which execjs support
PyV8 = "PyV8"
Node = "Node"
JavaScriptCore = "JavaScriptCore"
SpiderMonkey = "SpiderMonkey"
JScript = "JScript"
PhantomJS = "PhantomJS"
SlimerJS = "SlimerJS"
Nashorn = "Nashorn"

Related

Pyinstaller - pre-safe-import-module hook failed, needs fixing

I am trying to use pyinstaller to turn my .pyw file into an .exe. I've done this process a few times before and everything has worked, however, this time around it has shown this error:
**
SyntaxError: invalid syntax
pre-safe-import-module hook failed, needs fixing.** I realise that this has problem has already been raised here https://stackoverflow.com/questions/69151708/pyinstaller-python-pre-safe-import-module-hook-failed-needs-fixing But this solution did not work for me. The last error cmd showed was ** File "c:\users\user1\appdata\local\programs\python\python39\lib\site-packages\logging\__init__.py", line 618
raise NotImplementedError, 'emit must be implemented '\ **
In case it helps, here are the packages im using in my code:
from optparse import Values
import PySimpleGUI as sg
import os, shutil
import time
import ctypes
from pathlib import Path
import winshell
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fp.fp import FreeProxy
import winreg
import re
import threading

pyinstaller "unable to find a txt file when adding a binary"

When i was converting my script to exe using pyinstaller i got an error:-
Unable to find "c:\users\praveen\appdata\local\programs\python\python36\lib\site-packages\importlib_resources\version.txt" when adding binary and data files
You can view the full error here:
https://drive.google.com/file/d/1FmV5kdb7p6TgEZwKBFDmFIszC-Qha0BD/view?usp=sharing
my script has alot of imports, they are:-
import tkinter as tk
import os
import time
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PIL import ImageGrab
import numpy as np
import cv2
import pytesseract
import webview
what does that error mean? and why am i getting it?
You need to write the command correctly, example:
pyinstaller --add-data web_folder;web_folder --add-data db.sqlite;. gui.py
Description: title_of_folder_or_file;path_to_it (if your OS Windows use ";", else ":". On windows it's 100% but on linux or mac i don't know) for folder you need after ; set path to this folder, example web_folder;web_folder
Source - Official Documentation

TkMessageBox - No Module

import TkMessageBox
When I import TkMessageBox it displays the messsge 'ImportError: No module named 'TkMessageBox'.
As far as I know im using python 3.3.2 and Tk 8.5.
Am I using the wrong version of python or importing it wrong ?
Any answers would be extremely useful. Alternatively is there something similar in the version i am using?
In Python3.x things have changed a little bit:
>>> import tkinter
>>> import tkinter.messagebox
>>>
I mean what we call tkMessageBox in Python2.x becomes tkinter.messagebox in Python3.x
If you don't want to have to change the code for Python 2 vs Python 3, you can use import as:
try:
from tkinter import messagebox
except ImportError:
# Python 2
import tkMessageBox as messagebox
:edit:
However, tkinter is in a separate package in Debian due to Debian policies, so to avoid an incorrect fallback to Python 2 code I now use:
import sys
if sys.version_info.major >= 3:
from tkinter import messagebox
else:
import tkMessageBox as messagebox
Then using messagebox as follows will work in either version:
messagebox.showerror("Error", "Message.")
In Python 2.x, to import, you'd say import tkMessageBox. But in Python 3.x, it's been renamed to import tkinter.messagebox.
Hope it helped :))
for python 3.x
import tkinter
import tkinter.messagebox
from tkinter import messagebox sous Python 3
messagebox.showinfo(title=None, message=None, **options)

webbrowser modul windows service?

my example code:
import pyautogui
import webbrowser
import time
webbrowser.open_new_tab("http://127.0.0.1:8080/scripts/a.php")
time.sleep(5)
pyautogui.hotkey('tab')
pyautogui.typewrite(' lololo',interval=0.25)
pyautogui.hotkey('enter')
How can I start the module of webbrowser modul as aservice of windows ?

Windows Python 2.7 wxwidgets and 'gizmos'

Can anyone give me precise instructions on how to access the wx 'gizmos' module?
import wx.gizmos
ImportError: No module named gizmos
The code in question has this:
import wx
import string
import wx.gizmos
from wx.lib.mixins import treemixin
import Descriptor
'pip list' reports
wxPython-Phoenix (3.0.3.dev1830+0b5f910)
Do I have the right package installed? I should add that these files are present:
\python27\Lib\wxpython\wx-3.0-msw\wx\gizmos.py
\python27\Lib\wxpython\wx-3.0-msw\wx\_gizmos.pyd
[edit] For clarification, this seems to be OK so I'm reasonably sure the WX module is installed correctly.
import wx
import copy
# had to add .agw to get this to load
import wx.lib.agw.customtreectrl as CT
import DescriptorDetailsPanel
TAIA
Congrats, you have two installs of wx. You can use pkg_resources to get the one you want. Put the following at the top of the script:
__requires__ = ["wx >= 3.0"]
import pkg_resources
This will tell pkg_resources to set things up so that a version of wx of at least 3.0 will be available if you import wx rather than the default 2.x.
You can try to remove wxpython from pip install and reinstall wxpython from this site:
https://www.wxpython.org/download.php
It worked for me!

Categories