1、pyinstaller打包.py获取依赖文件的绝对路径导致打包错误、不提示错误但是不能使用问题?
    参考引用:pyinstaller打包-py获取依赖文件的绝对路径方法_Iv_zzy的博客-CSDN博客?
    切记,想获取当前路径,切勿在程序中使用“os.path.dirname(file)”。

    2、打包为console或debug模式,查看错误信息【推荐console模式,不推荐debug模式】 console模式举例:
    pyinstaller -c demo.py
    debug模式举例:
    pyinstaller -d all demo.py
    然后进入dist文件夹中,将demo.exe拖到命令行窗口(cmd或anaconda Prompt)执行即可,很容易发现出错提示。
    “Fail to execute script xxx”这种错误往往都是路径问题,仔细检查各文件路径、脚本里的路径、检查环境变量。
    必要时将路径用print 输出,在console模式下查看print出的路径正不正确,有时在pycharm中正常,pyinstaller打包后就有差异了,比如:os.path.dirname(file)。

    3、 防止pyinstaller找不到依赖包的情况?
    将程序中所有from import 全部改为import
    例如:
    #from configparser import ConfigParser #读取配置文件config.ini
    #config = ConfigParser() #为保证pyinstaller打包时依赖的兼容性,修改为如下:
    import configparser
    config = configparser.ConfigParser()
    4、清理与anaconda或python相关联的无用无效系统环境变量
    清理系统环境变量中跟python有关的无效无用变量,有时安装了anaconda或python多个版本,使用环境变量混乱。
    也可添加必要的path变量,环境变量PATH中加上没搜索到的文件例如:PyQt5的plugins的路径。
    5、更新pip和pyinstaller
    首先将pip更新至最新版:
    python -m pip install —upgrade pip
    再用新版pip更新pyinstaller
    pip install pyinstaller
    最后用pip安装程序中需要的包或模块
    pip install

    特别地:如果计划在虚拟环境中打包,那么就要在虚拟环境里安装pyinstaller。如果你没有在虚拟环境中安装pyinstaller,你同样可以使用pyinstaller命令,但是调用的是你系统原本的那个python编译器,内含很多关联库,导致即使在虚拟环境中,你打包的exe文件仍然非常大。
    6、对于显示包没有导入的?(也可在.spec文件中设置,再用pyinstaller demo.spec打包)
    这样写打包命令,pyinstaller指令后面添加上:
    —hidden-import queue。
    例如:pyinstaller -F —hidden-import queue demo.py
    7、一般而言,尽量不要在中文路径下打包。
    8、缺少微软的vc运行库(Microsoft Visual C++ 20**)。一般推荐安装“微软常用运行库合集”解决。
    9、pyinstaller打包报错找不到依赖pypiwin32或pywin32-ctypes的错误?PyInstaller cannot check for assembly dependencies?
    错误提示信息如下:
    PyInstaller cannot check for assembly dependencies.
    Please install pywin32-ctypes.
    pip install pywin32-ctypes

    解决方法:在python安装路径下找到Lib/site-packages/Pyinstaller目录下有个compat.py文件,在其中搜索
    fromwin32ctypes.pywin32 importpywintypes
    找到位置后:
    if iswin: try: from win32ctypes.pywin32 import pywintypes # noqa: F401_ from win32ctypes.pywin32 import win32api except ImportError: xxxx xxxx
    做如下修改:
    将两个from …import …都改为import…:
    if is_win: try: # from win32ctypes.pywin32 import pywintypes # noqa: F401 # from win32ctypes.pywin32 import win32api import pywintypes import win32api except ImportError: xxxx xxxx
    然后再重新运行打包脚本,打包成功。

    10、win7设置bat批处理文件的快捷方式以管理员身份运行?
    参考引用:

    image.png

    10.1 右键单击快捷方式点击属性;

    image.png

    10.2 设置快捷方式的高级按钮属性即可。