Python:找不到“__main__”模块

我有这个 python 代码,我想从 Windows Run 运行它。但是,当我尝试运行它时,cmd 会显示此消息。


C:\Users\myName\AppData\Local\Programs\Python\Python38-32\python.exe: can't find '__main__' module in 'C:\\Users\\myName\\OneDrive'


我正在使用 VS Code 在 python 3.8.3 32 位虚拟环境中编写我的程序。python程序称为pw.py,批处理文件称为pw.bat


pw.py


C:\Users\myName\OneDrive - 公司名称\04Programming\01 Visual Studio Code\LearningPython\pw.py


#! python3

# pw.py - An insecure password locker program.


import sys, pyperclip


PASSWORD = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',

            'blog': 'VmAlvQyKAxiVH5G8vo1if1MLZF3sdt',

            'luggage': '12345'}


if len(sys.argv) < 2:

    print('Usage: python pw.py [account] - copy account password')

    sys.exit()


account = sys.argv[1]   # first commmand line arg is the account name


if account in PASSWORD:

    pyperclip.copy(PASSWORD[account])

    print('Password for ' + account + ' copied to clipboard.')

else:

    print('There is no account named ' + account)

密码蝙蝠


C:\Users\myName\MyPythonScripts


@py.exe C:\Users\myName\OneDrive - companyName\04 Programming\01 Visual Studio Code\LearningPython\pw.py %*

@pause


慕森卡
浏览 211回答 1
1回答

扬帆大鱼

首先,检查一下你是否正确处理空格,这不是那么明显。尝试在批处理文件中添加空格 (  ) 和反斜杠 ( ) 前缀,如下所示:\ @py.exe C:\Users\myName\OneDrive\ -\ companyName\04\ Programming\01\ Visual\ Studio\ Code\LearningPython\pw.py %*@pause另一种方法是将路径用引号引起来,即:@py.exe "C:\Users\myName\OneDrive - companyName\04 Programming\01 Visual Studio Code\LearningPython\pw.py" %*@pause您还可以考虑添加以下内容:if __name__ == "__main__":    #code here使用PASSWORDSdict 之后,即:#! python3# pw.py - An insecure password locker program.import sys, pyperclipPASSWORD = {'email': 'F7minlBDDuvMJuxESSKHFhTxFtjVB6',            'blog': 'VmAlvQyKAxiVH5G8vo1if1MLZF3sdt',            'luggage': '12345'}if __name__ == "__main__":    if len(sys.argv) < 2:        print('Usage: python pw.py [account] - copy account password')        sys.exit()    # And so on...
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python