当我尝试使用pyinstaller构建可执行文件时,只创建了一个.spec文件,如何使用pyinstaller构建可执行文件

2024-05-13 09:13:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Anaconda提示符,在导航到python代码所在的文件夹后,我运行了命令 pyinstaller--onefile exercise9.py 我注意到只创建了一个名为exercise9.spec的文件。我没有看到dist文件夹,我想在其中找到我使用的教程中所述的.exe文件

下面是我试图执行的python代码

from getpass import getpass
def login():
     username = input("Please enter your username: ")
     password = getpass("Please enter your password: ")
     return [username, password]
try:
    login_details = login()
    if login_details[0] != "admin": 
        raise ValueError()
    elif login_details[1] != "password":
        print("Wrong Password")

    else:
        print("Login successful")
        input("Press enter to exit")
except ValueError:
    print("Wrong User name")

以下是exercise9.spec文件的内容

block_cipher = None

 a = Analysis(['exercise9.py'],
         pathex=['C:\\Users\\USER\\Desktop\\schoology\\exer9'],
         binaries=[],
         datas=[],
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher,
         noarchive=False)
 pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
 exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      [],
      name='exercise9',
      debug=False,
      bootloader_ignore_signals=False,
      strip=False,
      upx=True,
      upx_exclude=[],
      runtime_tmpdir=None,
      console=True )

请帮帮我,我也尝试过其他gui代码,但只创建了.spec文件,我使用的是windows 7


Tags: 文件代码文件夹falseusernameloginpassworddetails
1条回答
网友
1楼 · 发布于 2024-05-13 09:13:15

我已经能够通过导航到anaconda提示符中的scripts目录并输入以下命令来解决此问题:

python -m PyInstaller  onefile exercise9.py

相关问题 更多 >