Hello,
I made a simple code and examine it many times on vscode, but when I made .exe file from that by using pyinstaller --onefile, it didn't work.
Also I tries auto-py-to-exe to convert it and faced the same problem.
Platform which I ran the exe file and examine the code is windows 10.
Could you please let me know what happens and how I can solve it?
The source code is attached.
Thanks
Could you please, copy/paste your code in the post, using python
tags, or if it is too big/has multiple files - create a repo and share a link.
Not everyone will download untrusted file.
(Jun-24-2021, 06:55 AM)buran Wrote: [ -> ]Could you please, copy/paste your code in the post, using python
tags, or if it is too big/has multiple files - create a repo and share a link.
Not everyone will download untrusted file.
Thank you for mentioned it:
here is my code:
# Minimal System Inventory v1
## importing module
import os
import platform
import psutil
import socket
import subprocess
import datetime
import sys
import time
import wmi
#import win32com.client
#import winreg
#import winapps
import iis_bridge as iis
import wmicq # https://pypi.org/project/wmicq/
print('System Inventory is running, Please wait ...')
# Project Path
projectpath = (os.path.dirname(os.path.abspath(__file__)))
save_path = projectpath
file_name = "SystemInfo.txt"
completeName = os.path.join(save_path, file_name)
file1 = open(completeName, "w")
now = datetime.datetime.now()
original_stdout = sys.stdout
with open(completeName, 'w') as f:
sys.stdout = f
print('System Inventory')
print ("Current date and time : ", now)
# System Info
## getting the hostname by socket.gethostname() method
hostname = socket.gethostname()
print("Hostname : ", hostname)
## getting the IP address using socket.gethostbyname() method
try:
attributes = ['Description', 'IPAddress', 'MACAddress']
header, queryData = wmicq.query(wmicq.Category.NICCONFIG, attributes = attributes, where = "IpEnabled=True")
maxLen = max(len(x) for x in header)
for q in queryData:
print("NIC info : ", "{}: MAC: {}, IP: {}".format(q["Description"], q["MACAddress"], q["IPAddress"]))
except wmicq.QueryError as e:
print("Query error: {}".format(e))
ip_address = socket.gethostbyname(hostname)
print("Current IP Address : ", ip_address)
#Computer network name
#print(f"Computer network name: {platform.node()}")
#print(f"IP Address: {ip_address}")
#Machine type
print(f"Machine type: {platform.machine()}")
#Processor type
print(f"Processor type: {platform.processor()}")
#Platform type
print(f"Platform type: {platform.platform()}")
#Operating system
print(f"Operating system: {platform.system()}")
#Operating system release
print(f"Operating system release: {platform.release()}")
#Operating system version
print(f"Operating system version: {platform.version()}")
# CPU Information
myWMI = wmi.WMI ()
for processer in myWMI.Win32_Processor ():
print ("Current Clock Speed : %s" % (processer.CurrentClockSpeed))
print ("Name : %s" % (processer.Name))
print ("Cores : %s" % (processer.NumberOfCores))
#Physical cores
print(f"Number of physical cores: {psutil.cpu_count(logical=False)}")
#Logical cores
print(f"Number of logical cores: {psutil.cpu_count(logical=True)}")
#Current frequency
print(f"Current CPU frequency: {psutil.cpu_freq().current}")
#Min frequency
print(f"Min CPU frequency: {psutil.cpu_freq().min}")
#Max frequency
print(f"Max CPU frequency: {psutil.cpu_freq().max}")
#Total RAM
print(f"Total RAM installed: {round(psutil.virtual_memory().total/1000000000, 2)} GB")
#Available RAM
print(f"Available RAM: {round(psutil.virtual_memory().available/1000000000, 2)} GB")
#Used RAM
print(f"Used RAM: {round(psutil.virtual_memory().used/1000000000, 2)} GB")
#RAM usage
print(f"RAM usage: {psutil.virtual_memory().percent}%")
#Disk
print(f"Disk Info : {psutil.disk_partitions()}")
totalsize = psutil.disk_usage('C:\\').total / 2**30
#print('System Drive Infor: ',totalsize, ' GB')
for disk in psutil.disk_partitions():
if disk.fstype:
print(disk.device, psutil.disk_usage(disk.mountpoint) .total / 2**30 ,' GB')
# traverse the info
print ("<<< Windows System Information >>>")
Id = subprocess.check_output(['systeminfo']).decode('utf-8').split('\n')
new = []
# arrange the string into clear info
for item in Id:
new.append(str(item.split("\r")[:-1]))
for i in new:
print(i[2:-2])
# traverse the IIS info : https://pythonhosted.org/iis_bridge/
print("IIS Version %s" % iis.get_version())
# to install iis:
#iis.install()
# to reset iis:
#iis.iisreset()
# to list the pool names:
print("IIS Pools names: ", iis.get_pool_names())
# to list the site names:
print("IIS Websites: ", iis.get_site_names())
# Reset the standard output
sys.stdout = original_stdout
file1.close()
print ("Result File: ", completeName)
(Jun-24-2021, 06:38 AM)mhzr Wrote: [ -> ]it didn't work.
this is not very descriptive. What error do you get when you run the
exe
from cmd? I would guess there is missing imports (i.e. some of the third-party packages is not included with the bundle).
(Jun-24-2021, 07:18 AM)buran Wrote: [ -> ] (Jun-24-2021, 06:38 AM)mhzr Wrote: [ -> ]it didn't work.
this is not very descriptive. What error do you get when you run the exe
from cmd? I would guess there is missing imports (i.e. some of the third-party packages is not included with the bundle).
I don't get any error. what I see is the exe is running for unlimited long time and never closes until I close it.
How can I find which module is not included , I mean How I can find a debug log or such log to clear the problem?
Thank You
(Jun-24-2021, 07:42 AM)mhzr Wrote: [ -> ]How can I find which module is not included
if it was missing import it will raise an error immediately when you start it - at the time of imports.
is it running fine as script, before being converted to exe?
(Jun-24-2021, 07:42 AM)mhzr Wrote: [ -> ] (Jun-24-2021, 07:18 AM)buran Wrote: [ -> ]this is not very descriptive. What error do you get when you run the exe
from cmd? I would guess there is missing imports (i.e. some of the third-party packages is not included with the bundle).
I don't get any error. what I see is the exe is running for unlimited long time and never closes until I close it.
How can I find which module is not included , I mean How I can find a debug log or such log to clear the problem?
Thank You
You can't see anything about what was included with the --onefile option. You need to use the standard method of building to a folder first so you can ensure that all the imports were handled properly.
https://pyinstaller.readthedocs.io/en/st...o-one-file
I haven't used pyinstaller much in the past but have a couple big(ish) projects I'm about to try it on. See what you get using the folder method and if you still can't figure it out I'll try building your code too. I don't see anything problematic in your code except maybe the Windows IIS stuff.