"导入:未找到命令"运行Python脚本

时间:2016-08-07 05:21:33

标签: python

我是一名初学者,对编码知之甚少。 我正在尝试运行以下python脚本... https://github.com/Sdocquir/moneyonbots/blob/master/shopify3/shopify3.py

这样做时,我会收到以下消息

/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 1: __author__: command not found
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 3: import: command not found
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 4: import: command not found
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 5: import: command not found
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 6: import: command not found
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 7: import: command not found
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 8: import: command not found
from: can't read /var/mail/lxml
from: can't read /var/mail/selenium
from: can't read /var/mail/requests.adapters
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 15: syntax error near unexpected token `('
/Users/xxx/Downloads/moneyonbots-master/shopify3/shopify3.py: line 15: modes = [('Gift Card', 1), ('Credit Card', 2), ('Paypal', 3)]'

在剧本的开头,它说......

import requests
import sys, traceback
import re
import arrow
import time
import Tkinter as tk
from lxml import html
from selenium import webdriver
from requests.adapters import HTTPAdapter

我是否需要安装其他库来运行脚本?安装这些的命令是什么? 我正在使用mac OSX。 谢谢。

完整的脚本:https://github.com/Sdocquir/moneyonbots

1 个答案:

答案 0 :(得分:6)

当你的脚本由shell运行时,而不是Python解释器,就会发生这种情况。

将一个shebang放在脚本的第一行:

#!/usr/bin/env python

......或者,视情况而定

#!/usr/bin/env python3

...指定操作系统应该使用Python解释器运行它。

您可能确实需要安装一些第三方软件包,但在修复解释程序后,您将收到特定于导入失败的错误;此时,您可以使用您用于安装Python 3的相同软件包管理器(如果它是通过MacPorts或Homebrew或类似软件安装的),或者使用PyPi,virtualenv或类似软件。