Pyinstaller 不会打开 python 脚本的外部 .txt 文件
Pyinstaller won't open the external .txt files of the python script
编辑
这是我的代码:
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 和 --hidden-import pyperclip。
我 运行 它与 -d 和我得到的调试是:
PyInstaller Bootloader 3.x
LOADER: executable is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\deweycheck.exe
LOADER: homepath is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
LOADER: _MEIPASS2 is NULL
LOADER: archivename is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\deweycheck.exe
LOADER: No need to extract files to run; setting extractionpath to homepath
LOADER: SetDllDirectory(C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck)
LOADER: Already in the child - running user's code.
LOADER: Python library: C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\python35.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: Pre-init sys.path is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\base_library.zip;C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
LOADER: sys.prefix is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
LOADER: Setting runtime options
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\base_library.zip;C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
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 的输入
编辑
这是我的代码:
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 和 --hidden-import pyperclip。
我 运行 它与 -d 和我得到的调试是:
PyInstaller Bootloader 3.x
LOADER: executable is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\deweycheck.exe
LOADER: homepath is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
LOADER: _MEIPASS2 is NULL
LOADER: archivename is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\deweycheck.exe
LOADER: No need to extract files to run; setting extractionpath to homepath
LOADER: SetDllDirectory(C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck)
LOADER: Already in the child - running user's code.
LOADER: Python library: C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\python35.dll
LOADER: Loaded functions from Python library.
LOADER: Manipulating environment (sys.path, sys.prefix)
LOADER: Pre-init sys.path is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\base_library.zip;C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
LOADER: sys.prefix is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
LOADER: Setting runtime options
LOADER: Initializing python
LOADER: Overriding Python's sys.path
LOADER: Post-init sys.path is C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck\base_library.zip;C:\Users\aless\AppData\Local\Programs\Python\Python35\dist\deweycheck
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 的输入