简体   繁体   English

项目输出不会移动到输出文件夹(py installer)

[英]Project output will not be moved to output folder(py installer)

I'm trying to convert my script(thousand lines) to exe.我正在尝试将我的脚本(千行)转换为 exe。 I have nearly 50 modules for importing in my code.我有将近 50 个模块可以导入到我的代码中。 For converting, I used pyinstaller --onefile myscript.py , but it gave an error.对于转换,我使用了pyinstaller --onefile myscript.py ,但它给出了错误。 Also I used auto-py-to-exe program, but same error.我也使用了 auto-py-to-exe 程序,但同样的错误。 Then I made a simple gui for trying whether my converting method is right or wrong.然后我做了一个简单的 gui 来测试我的转换方法是对还是错。 Fortunately, it worked.幸运的是,它奏效了。 After that i just copy my 50modules to that simple-running script, then try to convert.之后我只是将我的 50modules 复制到那个简单运行的脚本中,然后尝试转换。 And i got same error.我得到了同样的错误。 However i can able to run myscipt in python(so modules are running).但是我可以在 python 中运行 myscipt(所以模块正在运行)。 I dont understand what the problem is.我不明白问题是什么。

I wrote my script with Python 3.7 and used pyinstaller both in Python 3.7 and 2.7.我用 Python 3.7 编写了我的脚本,并在 Python 3.7 和 2.7 中使用了 pyinstaller。 Below example run with two module and convertable to exe, but with those 50 modules, no way.下面的示例使用两个模块运行并可以转换为 exe,但是对于这 50 个模块,没有办法。

# -*- coding: utf-8 -*- 

import sys, os 
import wx
import wx.grid
import wx.lib.agw.aui as aui
import serial
import serial.tools.list_ports
import datetime 
import mplcursors 
import time
import math
import numpy as np
import _thread  
import copy
import colorsys
import functools
import matplotlib                                                                   ### .ticker
import matplotlib as mpl                                                            
import matplotlib.pyplot as plt                                                     
from math import pi
from matplotlib.figure import Figure                                                
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas 
from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as NavigationToolbar    
from matplotlib.widgets import Button
from matplotlib.widgets import SpanSelector
from mpl_toolkits.basemap import Basemap
from pygeodesy.sphericalNvector import LatLon  
from geographiclib.geodesic import Geodesic
from datetime import datetime as dt                    
from wx.lib import analogclock as ac                                                   
from wx.lib.delayedresult import startWorker
from wx.lib import masked
from wx.lib.masked import TextCtrl
from haversine import haversine
from skimage import io              #from PIL import *
try:
    from agw import speedmeter as SM
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.speedmeter as SM
try:
    from agw import pygauge as PG
except ImportError: # if it's not there locally, try the wxPython lib.
    try:
        import wx.lib.agw.pygauge as PG
    except:
        raise Exception("This demo requires wxPython version greater than 2.9.0.0")

#below modules are enough for run this
import wx
import os


wildcard = "Python source (*.txt)|*.txt|" \
            "All files (*.*)|*.*"
class MyFrame11 ( wx.Frame ):
    def __init__( self, parent ):
        wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
        self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
        bSizer2 = wx.BoxSizer( wx.HORIZONTAL )

        self.m_button121 = wx.Button( self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer2.Add( self.m_button121, 0, wx.ALL, 5 )

        self.m_textCtrl12 = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
        bSizer2.Add( self.m_textCtrl12, 0, wx.ALL, 5 )

        self.btn = True

        self.SetSizer( bSizer2 )
        self.Layout()
        self.Centre( wx.BOTH )
        # Connect Events
        self.m_button121.Bind( wx.EVT_BUTTON, self.btn_f )


    def btn_f( self, event ):
        if self.btn:
            self.m_textCtrl12.SetValue("hey")
            self.btn = False
        else:
            self.m_textCtrl12.Clear()
            self.btn = True



if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame11(None)
    frame.Show(True)
    app.MainLoop()

And traces like this:和这样的痕迹:

An error occurred, traceback follows:
Traceback (most recent call last):
File "c:\program files\python37\lib\site-packages\auto_py_to_exe\__main__.py", line 230, in convert
    pyi.run() # Execute PyInstaller
File "c:\program files\python37\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
File "c:\program files\python37\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\program files\python37\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\program files\python37\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
File "<string>", line 17, in <module>
File "c:\program files\python37\lib\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
    self.__postinit__()
File "c:\program files\python37\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
File "c:\program files\python37\lib\site-packages\PyInstaller\building\build_main.py", line 541, in assemble
    priority_scripts = self.graph.analyze_runtime_hooks(self.custom_runtime_hooks) + priority_scripts
File "c:\program files\python37\lib\site-packages\PyInstaller\depend\analysis.py", line 514, in analyze_runtime_hooks
    rthooks_nodes.append(self.run_script(path))
File "c:\program files\python37\lib\site-packages\PyInstaller\depend\analysis.py", line 219, in run_script
    return super(PyiModuleGraph, self).run_script(pathname, caller=caller)
File "c:\program files\python37\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1331, in run_script
    with open(pathname, 'rb') as fp:
FileNotFoundError: [Errno 2] No such file or directory: 'c:\\program files\\python37\\lib\\site-packages\\PyInstaller\\loader\\rthooks\\pyi_rth_nltk.py'

Project output will not be moved to output folder
Complete.

Any suggestion would be appreciated.任何建议将不胜感激。

You probably are running pyinstaller in cmd as admin, therefore changing you directory to C:\\Windows\\System32 before running pyinstaller try using cd %USERPROFILE%\\Desktop .您可能正在 cmd 中以管理员身份运行 pyinstaller,因此在运行pyinstaller之前将目录更改为C:\\Windows\\System32尝试使用cd %USERPROFILE%\\Desktop This will ensure that you are using a directory that you have permission to use.这将确保您使用的是您有权使用的目录。 %USERPROFILE% means your user folder, from there we go to your desktop. %USERPROFILE%表示您的用户文件夹,从那里我们转到您的桌面。 It might also be that you have a currupt installation of pyinstaller.也可能是您的 pyinstaller 安装已损坏。 Try using pip uninstall pyinstaller and then pip install pyinstaller .尝试使用pip uninstall pyinstaller ,然后pip install pyinstaller This just reinstalls pyinstaller.这只是重新安装pyinstaller。 The last solution might be that you do not have those modules with your .exe use --hidden import to add an import or module to your exe.最后一个解决方案可能是您的 .exe 中没有这些模块,请使用--hidden import向您的 exe 添加导入或模块。 You can do this as many times as you need to when you are running your command.在运行命令时,您可以根据需要多次执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM