Pyinstaller 不会打开 python 脚本的外部.txt文件


编辑

这是我的代码:

import pyperclip
text_file = open("dewey.txt", "rt")                     #Open the list containing the values
text = text_file.read().split('n')
text_file.close()

num = []
with open ('dewey num.txt', 'rt') as in_file:           #Open the list containing the keys
    for line in in_file:
        num.append(line[:3])
intenum = []
for i in num:
    intenum.append(int(i))                              #Make the keys as integers

dict1= dict(zip(intenum,text))                          #Merge the 2 lists in a dictionary
print ('This software will give you the subjects for each stack.')                                  #Instructions for the user
print ('I need to know the range first, please only use the first three numbers of the classmark.') #Instructions for the user
x=input('Please key in the starting number for this stack: ')                                       #Input for start
y=input('Please key in the last number for this stack: ')                                           #Input for stop
start = int(x)
stop = int(y)
values = [dict1[k] for k in range(start, stop + 1) if k in dict1]                                   #Call the values in range
print('The subject(s) for this section: ')
for i in values:                                                                                    #Print the values in range
    print (i)
output = 'n'.join (values)
pyperclip.copy(output)

它在python中正常工作,所以我使用Pyinstaller将其编译为.exe。

我现在设法有了一个exe文件,但我正在努力导入pyperclip。

除了最后一个命令外,exe都能工作。我尝试了-p dir,还尝试了隐藏导入pyperclip。

我用-d运行它,得到的调试结果是:

PyInstaller Bootloader 3.x
LOADER: executable is C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheckdeweycheck.exe
LOADER: homepath is C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheck
LOADER: _MEIPASS2 is NULL
LOADER: archivename is C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheckdeweycheck.exe
LOADER: No need to extract files to run; setting extractionpath to homepath
LOADER: SetDllDirectory(C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheck)
LOADER: Already in the child - running user's code.
LOADER: Python library: C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheckpython35.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: Pre-init sys.path is C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheckbase_library.zip;C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheck
LOADER: sys.prefix is C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheck
LOADER: Setting runtime options
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheckbase_library.zip;C:UsersalessAppDataLocalProgramsPythonPython35distdeweycheck
LOADER: Setting sys.argv
LOADER: setting sys._MEIPASS
LOADER: importing modules from CArchive
LOADER: extracted struct
LOADER: callfunction returned...
LOADER: extracted pyimod01_os_path
LOADER: callfunction returned...
LOADER: extracted pyimod02_archive
LOADER: callfunction returned...
LOADER: extracted pyimod03_importers
LOADER: callfunction returned...
LOADER: Installing PYZ archive with Python modules.
LOADER: PYZ archive: out00-PYZ.pyz
LOADER: Running pyiboot01_bootstrap.py
LOADER: Running dewey.py

我不知道现在该怎么做:\有什么意见吗?

最后,我使用命令"pyi-makespec"导入了所有依赖项,然后需要额外的步骤来生成实际的exe文件。pyinstaller的文档非常广泛和准确。感谢@Repiklis的输入

相关内容

  • 没有找到相关文章

最新更新