简体   繁体   English

当 python ttp 模块就位时使用 pyinstaller exe 时出错

[英]error using pyinstaller exe when python ttp module is in place

I am trying convert my.py file to an exe file using pyinstaller.我正在尝试使用 pyinstaller 将 my.py 文件转换为 exe 文件。 The.py file perfectly work fine, however, I am facing an issue after the program is converted to.exe file. .py 文件完全可以正常工作,但是,在程序转换为 .exe 文件后,我遇到了一个问题。 The problem is shared right below.问题在下面共享。 ttp.lazy_import_functions: failed to save problem with File not found indication. ttp.lazy_import_functions:无法保存文件未找到指示的问题。

I did a search in google if any similar error, it looks there is only one similar discussion in github which is not the %100 same problem.如果有任何类似的错误,我在谷歌中进行了搜索,它看起来在 github 中只有一个类似的讨论,这不是 %100 相同的问题。 Because I am facing an issue when using.exe file.因为我在使用 .exe 文件时遇到问题。 See https://github.com/dmulyalin/ttp/issues/54参见https://github.com/dmulyalin/ttp/issues/54

However, I have checked ttp/ttp.py file, I can see following lazy_import_functions with the path_to_cache.但是,我检查了 ttp/ttp.py 文件,我可以看到以下带有 path_to_cache 的 lazy_import_functions。

log.info("ttp.lazy_import_functions: starting functions lazy import")

# try to load previously pickled/cached _ttp_ dictionary
path_to_cache = os.getenv("TTPCACHEFOLDER", os.path.dirname(__file__))
cache_file = os.path.join(path_to_cache, "ttp_dict_cache.pickle")

As it is also shown above picture, it looks that.exe file trying to find ttp/ttp.py file under _MEIXXXX cache file.正如上图所示,看起来 .exe 文件试图在 _MEIXXXX 缓存文件下找到 ttp/ttp.py 文件。

I have actually created a the following patch with the following changes in my ttp.py file to make.exe file work, however I have a few concerns here if someone explain it, I appricated it.我实际上已经创建了一个以下补丁,在我的 ttp.py 文件中进行了以下更改以使 make.exe 文件工作,但是如果有人解释它,我在这里有一些担忧,我应用了它。

Changes in my ttp.py:我的 ttp.py 的变化:

print(path_to_python_3x)
if path_to_python_3x:
    os.startfile(f"{path_to_python_3x}\\patch.py")

def lazy_import_functions():
    """function to collect a list of all files/directories within ttp module,
    parse .py files using ast and extract information about all functions
    to cache them within _ttp_ dictionary
    """
    _ttp_ = {
        "macro": {},
        "python_major_version": version_info.major,
        "global_vars": {},
        "template_obj": {},
        "vars": {},
    }
    log.info("ttp.lazy_import_functions: starting functions lazy import")

    # try to load previously pickled/cached _ttp_ dictionary
    path_to_temp_file = tempfile.gettempdir()
    _MEI_regex = "_MEI.*"
    for temp_file in os.listdir(path_to_temp_file):
        if re.search(_MEI_regex, temp_file):
            path_to_temp_mei = path_to_temp_file +f"\\{temp_file}"
            path_to_temp_ttp = f"{path_to_temp_mei}" + "\\ttp"
            path_to_cache = os.getenv("TTPCACHEFOLDER", path_to_temp_ttp)
            cache_file = os.path.join(path_to_cache, "ttp_dict_cache.pickle")
        else:
            path_to_cache = os.getenv("TTPCACHEFOLDER", os.path.dirname(__file__))
            #print(path_to_cache)
            cache_file = os.path.join(path_to_cache, "ttp_dict_cache.pickle")

With this patch file I am copying ttp/ folder includes ttp.py into _IMEXXXX cache file, so that.exe file finds the path, and worked fine, thankfully.使用此补丁文件,我将 ttp/ 文件夹(包括 ttp.py)复制到 _IMEXXXX 缓存文件中,以便 .exe 文件找到路径,并且工作正常,谢天谢地。

import os.path
import os
import sys
import tempfile
import shutil
import re

path_to_python_3x = os.path.dirname(sys.executable)
# print(path_to_python_3x)
# print(os.getcwd())

path_to_site_packages = path_to_python_3x + "\\Lib\\site-packages"
#print(path_to_site_packages)
path_to_site_ttp = path_to_site_packages +"\\ttp"
#print(path_to_site_ttp)

_MEI_regex = "_MEI.*"
_MEI_regex_a_list = []
while True:
    path_to_temp_file = tempfile.gettempdir()
    for temp_file in os.listdir(path_to_temp_file):
        if re.search(_MEI_regex, temp_file):
            path_to_temp_mei = path_to_temp_file +f"\\{temp_file}"
            _MEI_regex_a_list.append(path_to_temp_mei)
            path_to_temp_ttp = os.path.join(path_to_temp_mei, "ttp")
            try:
                if "ttp" not in os.listdir(path_to_temp_mei):
                    shutil.copytree(path_to_site_ttp, path_to_temp_ttp)
            except Exception as e:
                print(e)

My queries here are that:我在这里的查询是:

  1. Why the program does not work when installing with pyinstaller?为什么用pyinstaller安装程序不运行?
  2. Why it checks /ttp/ttp.py file under under Temp?为什么它检查 Temp 下的 /ttp/ttp.py 文件?
  3. Any way to change cache directory when converting with pyinstaller?使用 pyinstaller 转换时有什么方法可以更改缓存目录?
  4. As you can see, I have a workaround for now.如您所见,我现在有一个解决方法。 However, I won't work if cache file started to be kept other than Temp/_IMEXXXX.但是,如果开始保留缓存文件而不是 Temp/_IMEXXXX,我将无法工作。 Because my regex string chooses the files startswidth _IME.因为我的正则表达式字符串选择文件 startswidth _IME。 Not sure if any possiblity here as well.不确定这里是否也有任何可能性。

From what i see, the ttp module tries to access its files and has references to the installation path for ttp which it cannot get to using the os module after its bundled by pyinstaller.据我所知,ttp 模块尝试访问它的文件并引用了 ttp 的安装路径,在它被 pyinstaller 捆绑后无法使用 os 模块。

One simpler workaround than changing the module files and applying the patch file that you did, would be to just copy the installation folders of the ttp module to the bundle output folder using pyinstaller itself or do it manually.一种比更改模块文件和应用您所做的补丁文件更简单的解决方法是使用 pyinstaller 本身将 ttp 模块的安装文件夹复制到 bundle output 文件夹或手动执行。 This way it would find all the ttp module files which it was not after the bundle process using pyinstaller.这样它会找到所有在使用 pyinstaller 的捆绑过程之后不存在的 ttp 模块文件。

I was facing the same issue and it fixed it for me.我遇到了同样的问题,它为我解决了这个问题。

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

相关问题 Python 键盘模块在使用 pyinstaller 转换为 exe 时不捕获击键 - Python keyboard module not capturing keystrokes when coverted to exe using pyinstaller 使用 python 中的 ttp 模块忽略数据 - ignoring data using ttp module in python 转换为exe时出现Python pyinstaller错误 - Python pyinstaller error when converting to exe Python pyinstaller 将 py 转换为 exe 时出错 - Python pyinstaller error when converting py to exe 执行 .exe 时没有名为“img2pdf”的模块 - pyinstaller - error No module named 'img2pdf' when executing .exe - pyinstaller 如何在python中使用pyinstaller和sounddevice模块获取有效的EXE文件 - How to get a working EXE file using pyinstaller with the sounddevice module in Python 使用 pyinstaller 时出现“No module named util”错误 - 'No module named util' error when using pyinstaller 使用 pyinstaller 将 python 文件转换为 an.exe 文件时出现 opencv 错误 - opencv error when converting a python file to an .exe file with pyinstaller 使用 PyInstaller 将 python 3.7 脚本转换为 exe 时出错:ModuleNotFoundError - Error while converting python 3.7 script to exe using PyInstaller: ModuleNotFoundError 使用pyinstaller和scipy模块将py文件转换为exe文件时出错。 知道可能是什么问题吗? - Error when converting py file to exe file using pyinstaller and scipy module. Any idea what could be the problem?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM