无法使.py程序在Windows 10上正常运行(它们在Windows 7上运行良好)。可能是权限问题

时间:2019-02-05 20:49:57

标签: python python-3.x windows powershell service

几个月前,我在python中创建了一个程序,用于自动编辑和处理公司成像技术人员拍摄的照片,以准备将其发布在我们的网站上。通过python解释器运行程序只是一种临时措施,直到我可以用更适合该应用程序的语言重写代码并获得适当的二进制文件,但是我弹出了其他项目,结果运行得比预期的慢,因此,我们的技术人员仍在双击.py文件来编辑其图像,而不是.exe文件。在我们设置了两个都运行Windows 10的新映像站之前,这不是问题。(安装并测试了程序的其他站点都在Windows 7上运行),并被告知要在这些新站点上安装程序。除非我以管理员身份运行,否则什么都不会运行。我能够解决一些问题,但不能解决其他问题,并且确实可以使用一些帮助。这是程序,问题和一些相关代码示例的细目分类,希望可以使人们了解我应该怎么做。

因此,此应用包含两个文件。一个是作为Windows服务安装的守护程序,该守护程序在后台运行,监视扫描和照片的文件夹,然后在看到图像时运行一系列编辑功能,并将编辑的文件保存到另一个文件夹。第二个是简单的GUI,可让成像技术启动和停止守护程序,并在必要时进行手动编辑。核心文件工作正常。他们已经在8个成像站上运行了近9个月,而且运行顺利。问题在于,在这些新的Windows 10系统上,程序以某种方式“锁定”了它们所需的系统资源。只要以管理员身份启动命令提示符,我就可以安装该守护程序(否则,我将收到“访问被拒绝”错误),但是一旦安装,它将无法运行。每当我尝试启动它时,它都会启动并立即再次停止。此外,我可以用相同的方式启动GUI(通过以管理员身份打开命令行管理程序的命令行),但无法通过双击或等价地将文件拖到python.exe来打开它。在这两种情况下,就像守护程序一样,它启动并再次停止。

如前所述,守护程序和GUI已安装并在运行Windows 7的多台计算机上工作。这不是因为我没有启动循环或类似操作而无法打开GUI。这里发生了一些奇怪的事情,我不知道这是什么,但这似乎与Windows 7和Windows 10之间的安全设置有所不同有关,但这仅是推测。如果有人知道真正的问题可能是什么,或者我可以尝试解决某些问题,那就太好了。

由于我不确定问题的根源在哪里,因此我将发布与我的文档直接交互的,与操作系统直接交互的每个部分的最小化代码以及安装说明。衷心感谢您提供的任何帮助。

守护进程

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()

GUI

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!

0 个答案:

没有答案