简体   繁体   English

OsX Python 3.5 Bad Interpreter:没有这样的文件或目录

[英]OsX Python 3.5 Bad Interpreter: no such file or directory

I am trying to run the following code from the terminal window.我正在尝试从终端窗口运行以下代码。 I am following the tutorial found on this website https://automatetheboringstuff.com/chapter6/ .我正在关注本网站https://automatetheboringstuff.com/chapter6/上的教程。 The name of my file is "pw.py" I ran chmod +x pw.py to make it executable from the terminal window.我的文件名为“pw.py”,我运行 chmod +x pw.py 使其可以从终端窗口执行。 However, when I run ./pw.py I get an error saying "-bash: ./pw.py: python: bad interpreter: No such file or directory".但是,当我运行 ./pw.py 时,我收到一条错误消息:“-bash: ./pw.py: python: bad interpreter: No such file or directory”。 Any Idea what I missed?知道我错过了什么吗? Thanks for the help!感谢您的帮助!

#! /usr/bin/python
# pw.py - An insecure password locker program.

PASSWORDS = {'email' : 'F7minlBDDuvMJuxESSKHFhTxFtjVB6' ,
             'blog' : 'VmALvQyKAxiVH5G8v01if1MLZF3sdt' ,
             'luggage' : '12345'}
import sys, pyperclip
if len(sys.argv) < 2:
    print('Usage: python pw.py[account] - copy account password')
    sys.exit()

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

if account in PASSWORDS:
    pyperclip.copy(PASSWORDS[account])
    print('Password for ' + account + ' copied to clipboard.')
else:
    print('There is no account named ' + account)

I figured out my problem.我想出了我的问题。 I was not executing it in the terminal correctly.我没有在终端中正确执行它。 I was entering './pw.py' when I needed to enter 'python pw.py' in order for it to run the script.当我需要输入 'python pw.py' 以便它运行脚本时,我正在输入 './pw.py'。 Thanks for the help.感谢您的帮助。

What you have done looks correct from a python perspective.从 python 的角度来看,你所做的看起来是正确的。 the #! #! is called a shebang / shabang and it informs the OS what interpreter to call in order to execute this script.被称为shebang / shabang,它通知操作系统调用什么解释器来执行这个脚本。

So I would guess that Python is installed in a different location then what has been supplied.因此,我猜想 Python 安装在与提供的位置不同的位置。 Remember when this is called the full path needs to be supplied.请记住,当它被调用时,需要提供完整路径。 Try running which python to get the location of the interpreter and place that at line 1尝试运行which python以获取解释器的位置并将其放在第 1 行

I started getting this error when running pip python command, this started happening after a system-wide change in $HOME path, which apparently broke some stuff like pip (the old $HOME path seems hardcoded somewhere in the python installation).我在运行pip python 命令时开始收到此错误,这开始发生在 $HOME 路径中的系统范围更改之后,这显然破坏了pip之类的东西(旧的 $HOME 路径似乎在 python 安装中的某处进行了硬编码)。

I fixed it by re-installing pip (following this ):我通过重新安装 pip 来修复它(按照这个):

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && python get-pip.py

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM