So ive been trying to get the hwid of a device with a app im making however i cant seem to get the hwid when compiled without a command line.
import subprocess
import PySimpleGUI as sg
import os
a = subprocess.run("wmic csproduct get uuid",capture_output=True,text=True)
x = str(a.stdout).rstrip()
x = x.splitlines()
print(x[2])
sg.popup(x[2])
#wmic csproduct get uuid
The code works perfectly in vscode (also im on python 3.9 if that matters).
Related
I'm trying to get a code scheduled in windows:
import requests
from datetime import date
import pandas as pd
import sqlalchemy
from sqlalchemy import create_engine
server= 'xxxxx'
database='xxxxx'
driver_sql= 'ODBC Driver 17 for SQL Server'
database_con= f'mssql://#{server}/{database}?driver={driver_sql}'
engine= sqlalchemy.create_engine(database_con)
connection = engine.connect()
adr='https://api.swaggystocks.com/wsb/sentiment/ticker'
r = requests.get(adr)
json = r.json()
pdbasses= pd.DataFrame(json["data"])
pdbasses["timestamp"] = pd.to_datetime("today")
pdbasses["timestamp"] = pdbasses["timestamp"].dt.strftime("%Y-%m-%d")
pdbasses.to_sql("swaggy", connection, if_exists='append',index=False)
direct =r'D:\SQL\getdatafromhere\file'+str(date.today())+".csv"
pdbasses.to_csv(direct, index=False)
the problem is, when I put it through pyinstaller it says I'm missing packages that I can't even install via pip MySQLdb,Psycob2 etc.
Then when the exe file gets put out, I run it and it just blips for a second and doesn't do anything. The code works in PyCharm. I tried running pyinstaller through pycharm, but I get a Linux exe file/spec file. I tried converting that one to an exe file, but still doens't work.
Thank you for your time
I try to run a simple_3dviz script, but I always get the following error:
File "...venv/lib/python3.8/site-packages/moderngl/context.py", line 1228, in program
res.mglo, ls1, ls2, ls3, ls4, ls5, res._subroutines, res._geom, res._glo = self.mglo.program(
moderngl.error.Error: cannot create program
I have already installed PyOpenGL and PyOpenGL-accelerate, but the error stays the same.
My Python script:
from simple_3dviz import Mesh
from simple_3dviz.window import show
from simple_3dviz.utils import render
...
show(
Mesh.from_voxel_grid(voxels=workpiece.voxels),
light=(-1,-1,1)
)
I want to run my python API continuously (means program API will all-time active if call then it work) even if a system restarts my python API automatically restart.
I have API URL: http://localhost:8002/city_id_pred?id=1,2 through this URL calling python API.
Program:
import web
import pyodbc
import re
import numpy as np
#from wordcloud import WordCloud, STOPWORDS
from collections import Counter
from sklearn.externals import joblib
import pandas as pd
cnxn = pyodbc.connect('')
cursor = cnxn.cursor()
urls = (
'/city_id_pred?', 'Predict'
#'/', 'MyApplication'
)
class Predict(web.application):
def run(self, port=8080, *middleware):
func = self.wsgifunc(*middleware)
return web.httpserver.runsimple(func, ('0.0.0.0', port))
print("Start class...")
def GET(self):
#here prediction model
if __name__ == "__main__":
app = Predict(urls, globals())
app.run(port=8002)
Please suggest
Actually, I want to run on window server but currently using in windows OS.
As #Mubarak said, you basically want to convert it to a .exe and then add that .exe to startup.
I would recommend that you do this by using PyInstaller and then following this tutorial on how to add that .exe to your startup.
Following step will help you:
Make your python code like example.py
Convert example.py to example.exe file by using auto-py-to-exe https://pypi.org/project/auto-py-to-exe/
Open Task Schedular in your window system
Create Task->Gentral Tab ->Give Name,Location
Trigger Tab->Bigin the Task->On Startup
Hope this helps
Following given steps,.
1.Convert your python file to .exe format(https://pypi.org/project/auto-py-to-exe/)
Make simple batch file to run the .exe file which your python file.
#echo off
cd "C:\Program Files\Google\Chrome\Application\"
Start chrome.exe
start – "C:\Program Files\Microsoft Office\Office15\WINWORD.EXE"
"C:\Work\MUO\How to Batch Rename.docx"
cd "C:\Program Files (x86)\VMware\VMware Player"
start vmplayer.exe
exit
Hope your understood,....
I tried upload scenario with keyboard press simulation through ctypes package in python for selenium webdriver. It is working fine with my local machine installed with windows 8.1.
But when i run the same code in my development server which is a linux box, that will call a remote machine of windows 7 OS, i got error like windll not found in this part of my code
def SendInput(*inputs):
nInputs = len(inputs)
LPINPUT = INPUT * nInputs
pInputs = LPINPUT(*inputs)
cbSize = ctypes.c_int(ctypes.sizeof(INPUT))
return ctypes.windll.user32.SendInput(nInputs, pInputs, cbSize)
So I did change my code to a if else statement which prompts if the OS is windows got to above snippet of code else go to below snippet of code,
cdll.LoadLibrary("libc.so.6")
Xtst = cdll("libXtst.so.6")
Xlib = cdll("libX11.so.6")
dpy = Xtst.XOpenDisplay(None)
def SendInput(txt):
for c in txt:
sym = Xlib.XStringToKeysym(c)
code = Xlib.XKeysymToKeycode(dpy, sym)
Xtst.XTestFakeKeyEvent(dpy, code, True, 0)
Xtst.XTestFakeKeyEvent(dpy, code, False, 0)
Xlib.XFlush(dpy)
But after adding this i am getting error in my linux box like
TypeError: 'LibraryLoader' object is not callable.
I did search for resources over internet, but i was not able to get them. Can someone help me to get it through.
I have developed a python script for making a serial communication to a digital pump. I now need to make an executable out of it. However even though it works perfectly well when running it with python and py2exe does produce the .exe properly when I run the executable the following error occurs:
File: pump_model.pyc in line 96 in connect_new
File: serial\__init__.pyc in line 71 in serial_for_url
ValueError: invalid URL protocol 'loop' not known
The relevant piece of my code is the following:
# New serial connection
def connect_new(self, port_name):
"""Function for configuring a new serial connection."""
try:
self.ser = serial.Serial(port = port_name,\
baudrate = 9600,\
parity = 'N',\
stopbits = 1,\
bytesize = 8,\
timeout = self.timeout_time)
except serial.SerialException:
self.ser = serial.serial_for_url('loop://',\
timeout = self.timeout_time) # This line BLOWS!
except:
print sys.exc_info()[0]
finally:
self.initialize_pump()
I should note that the application was written in OSX and was tested on Windows with the Canopy Python Distribution.
I had the exact same problem with "socket://" rather than "loop://"
I wasn't able to get the accepted answer to work however the following seems to succeed:
1) Add an explicit import of the offending urlhandler.* module
import serial
# explicit import for py2exe - to fix "socket://" url issue
import serial.urlhandler.protocol_socket
# explicit import for py2exe - to fix "loop://" url issue (OP's particular prob)
import serial.urlhandler.protocol_loop
# use serial_for_url in normal manner
self._serial = serial.serial_for_url('socket://192.168.1.99:12000')
2) Generate a setup script for py2exe (see https://pypi.python.org/pypi/py2exe/) -- I've installed py2exe to a virtualenv:
path\to\env\Scripts\python.exe -m py2exe myscript.py -W mysetup.py
3) edit mysetup.py to include option
zipfile="library.zip" # default generated value is None
(see also http://www.py2exe.org/index.cgi/ListOfOptions)
3) build it:
path\to\env\Scripts\python.exe mysetup.py py2exe
4) run it
dist\myscript.exe
Found it!
It seems that for some reason the 'loop://' arguement can't be recognised after the .exe production.
I figured out by studying the pyserial/init.py script that when issuing the command serial.serial_for_url(‘loop://') you essentially call:
sys.modules['serial.urlhandler.protocol_loop’].Serial(“loop://“)
So you have to first import the serial.urlhandler.protocol_loop
and then issue that command in place of the one malfunctioning.
So you can now type:
__import__('serial.urlhandler.protocol_loop')
sys.modules[‘serial.urlhandler.protocol_loop’].Serial("loop://")
After this minor workaround it worked fine.