webbrowser modul windows service? - python

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 ?

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

Run code after subprocess calls a program?

I am trying to add code after I successfully open a program with a subprocess, but it's not working.
Can anyone tell me why?
import win32api, win32con
import subprocess
subprocess.call(['C:\ProgramData\Microsoft\Windows\Start
Menu\Programs\Adobe Premiere Pro 2022.lnk'],shell=True)
#This code doesn't run after subprocess
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
click(50,40)

Display print messages in console PyInstaller

I'm using PyInstaller to convert my Python file to .exe; however, I see that upon running the executable file, I don't see any print messages in the terminal which I use for my reference - it's just blank (no print messages).
Command I used: pyinstaller --onefile -w myfile.py
I use Selenium module in my Python file, which uses chromedriver.exe, so after running the generated .exe file, this is what it shows:
Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from selenium.common.exceptions import TimeoutException
from time import sleep
import random
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
print("Opened the browser")
Pictures:
I need to see the print messages. Tried searching for answers but couldn't find any solutions!
How do I resolve this?
If you run your .exe from a terminal like PowerShell it will probably show the output you're looking for. The window in the screenshot looks like it is coming from the Selenium driver.
If you want this to work when double-clicking on the .exe, rebuild without the -w flag:
-w, --windowed, --noconsole
Windows and Mac OS X: do not provide a console window for standard i/o. On Mac OS this also triggers building a Mac OS .app bundle. On Windows this option is automatically set if the first script is a ‘.pyw’ file. This option is ignored on *NIX systems.

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

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

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"

Categories