无法使.py程序在Windows10上正常运行(在Windows7上运行良好)。可能是权限问题

2024-04-26 09:40:36 发布

您现在位置:Python中文网/ 问答频道 /正文

几个月前,我用python创建了一个程序,可以自动编辑和处理我公司的成像技术人员拍摄的照片,以便将它们发布到我们的网站上。通过python解释器运行这个程序本来是一个临时措施,直到我可以用一种更适合这个应用程序的语言重写代码并得到一个合适的二进制文件,但是我弹出了其他项目,结果比预期的慢,所以,不是.exe文件,我们的技术人员仍然在双击一个.py文件来编辑他们的图像。这不是一个问题,直到我们建立了两个新的成像站,都运行视窗10(其他站,在那里的程序是建立和测试,都运行视窗7),我被告知要安装我的程序在这些新的站。除非我以管理员身份运行它,否则什么都不会运行。我能解决一些问题,但不能解决其他问题,我真的需要一些帮助。这里是一个程序,问题,和一些相关的代码样本的分解,希望给那里的人一个我应该做什么的想法。你知道吗

所以这个应用程序由两个文件组成。一个是后台程序,作为Windows服务安装,它在后台运行,监视文件夹中的扫描和照片,然后在看到图像时运行一系列编辑功能,并将编辑过的文件保存到另一个文件夹中。第二个是一个简单的GUI,它允许成像技术启动和停止守护进程,并在必要时进行手动编辑。核心文件工作正常。它们在8个成像站上运行了近9个月,没有任何问题。问题是,在这些新的windows10系统上,程序在某种程度上被“锁定”在它们运行所需的系统资源之外。只要以管理员身份启动命令提示符,我就可以安装守护程序(否则会出现“拒绝访问”错误),但一旦安装,它就不会运行。每当我试图启动它,它就会启动,然后立即停止。另外,我可以用同样的方式启动GUI(通过命令行,Shell以administrator的身份打开),但不能通过双击或将文件拖到命令行来打开它python.exe. 在这两种情况下,与守护进程一样,它会再次启动和停止。你知道吗

如前所述,守护进程和GUI已安装并在运行windows7的多台计算机上工作。这不是一个GUI没有打开,因为我没有启动循环或类似的东西。这里发生了一些奇怪的事情,我不知道是什么,但这似乎与Windows7和Windows10在安全设置上的一些差异有关,但这只是猜测。如果有人知道真正的问题是什么,或者我可以尝试解决一些事情,那就太好了。你知道吗

因为我不确定问题的原因是什么,所以我将发布与操作系统直接交互的每个部分的最小化代码,以及从我的文档中复制的安装说明。衷心感谢您能提供的任何帮助。你知道吗

守护进程

class SMWinservice(win32serviceutil.ServiceFramework):

    """This is a windows service that will watch the scan daemon folder and process 
    jpg images as they are scanned.
    """
    _svc_name_ = 'Scan Daemon'
    _svc_display_name_ = 'Scan Daemon'

    @classmethod
    def parse_command_line(cls):
        win32serviceutil.HandleCommandLine(cls)

    def __init__(self, args):
        win32serviceutil.ServiceFramework.__init__(self, args)
        self.hWaitStop = win32event.CreateEvent(None, 0, 0, None)


    def SvcStop(self):
        self.stop()
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        self.start()
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_, ''))
        self.main()

    def start(self):
        self.isrunning = True


    def stop(self):
        self.isrunning = False

    def main(self): 

        image_list=[]
        d=0
        def rotncrop(file):                          
            im=comiccrop(filename, r'C:\Users\%s\Pictures\My Scans\processed\comic_%d.jpg' %(desktop, d))
            image_list.append(im)
            os.rename(filename,r'C:\Users\%s\Pictures\My Scans\originals\image_%d.jpg' %(desktop, d))
        while self.isrunning:                       
            for filename in glob.glob(r'C:\Users\%s\Pictures\My Scans\scan daemon\*.jpg' %desktop):
                file_size = os.stat(filename).st_size
                if file_size > 100000:
                    d=d+1
                    time.sleep(1)
                    rotncrop(filename)
            time.sleep(0.5)
if __name__ == '__main__':
   SMWinservice.parse_command_line()

图形用户界面

class maingui:
    def __init__(self, master):
        self.master=master
        master.title("Virtual Straight Edge")

        self.v = tkinter.StringVar()
        self.lotsofentries=Entry(master,textvariable=self.v)
        self.lotsofentries.pack(side='somewhere')

        self.lotsofbuttons=Button(text='do things', command=self.somefunction)
        self.lotsofbuttons.pack(side='top')

    def somefunction(self):
        stuff happens

root = Tk()
theta=0
gui = maingui(root)
gui.updatetext()
root.mainloop()

安装说明

1. Download anaconda python for windows.
2. Copy the “Virtual Straight Edge” folder into AppData\Local\Continuum\anaconda3.
3. Open the start menu and right click on “Computer”.
4. Scroll down and select “Properties”.
5. Select “Advanced System Settings”.
6. Select “Environment Variables”.
7. Scroll down to “PATH” and select “Edit”.
8. Add the “Virtual Straight Edge” folder and “anaconda3\python.exe” to your path, separated by semi-colons.
9. If on a scanner, double click on “setup.py”. If on a photostation, double click on “photostation setup.py”. When asked what program to use to run this file, select “Browse” and navigate to the anaconda3 folder. Select “python.exe” and check the box that says “Always use this program to open this type of file.”
10. Allow the setup to run. It should take less than a second. Navigate to the Pictures\My Scans folder and verify that four new folders have been created, named “processed”, “originals”, “VSE Images”, and “scan daemon” (or “photo daemon”).
11. Open the command prompt and change directories to the anaconda3 folder.
12. If on a scanner, install the daemons as windows services by typing “python.exe daemon.py install” and “python.exe cropdaemon.py install”. If on a photostation, type “python.exe photodaemon.py install” and “python.exe cropdaemon (photostation).py install”.
13. Press Ctrl+R and type services.msc in the entry field. This will open the Windows Services Manager. Verify that the “Scan Daemon” (or “Photo Daemon”) and “Crop Daemon” are listed as windows services and close the Windows Services Manager.
14. Create a shortcut to Virtual_Straight_Edge.py and add it to the My Scans folder and the desktop if desired. You are now set up to use Virtual Straight Edge!

Tags: and文件thetopyself程序编辑