我不知道为什么,但是我不能通过终端运行python脚本。你知道吗
我的剧本:
定义_区域.py你知道吗
print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
终端:
pik:scripts katja$ python define_regions.py
pik:scripts katja$
它不执行它不知何故,我不明白为什么。你知道吗
先谢谢你。你知道吗
编辑:
pik:scripts katja$ python
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
python -V
Python 2.7.6
pik:scripts katja$ which python
/usr/local/bin/python
pik:scripts katja$ python -c "print 'hello' "
hello
编辑2: 对脚本的修改也不起作用
#!/usr/local/bin/python
print "Hello World!"
您是否尝试打开python终端(只是为了检查python是否正在运行?):键入python并输入
你在脚本所在的文件夹里吗?你知道吗
(执行list(ls)命令检查您是否看到脚本文件,否则,请使用cd将dir更改为脚本的位置)
有时需要在运行的脚本之前加一个点(在linux中,但osx非常类似),所以python./define_区域.py你知道吗
你能说:
在你的档案上面?你知道吗
你是怎么创建这个文件的?对OSX编辑器不是很熟悉。。。。但是你需要使用最简单的编辑器。。。避免文件中出现各种非ascii字符(如行尾…)。你知道吗
Add shebang line in the beginning your python script
和make your python script executable使用shell中的chmod。你知道吗
然后您将能够像您试图实现的那样执行python脚本。你知道吗
添加shebang意味着人们可以根据需要直接调用脚本(假设它被标记为可执行);省略shebang意味着必须手动调用python。你知道吗
运行程序的最终结果不会受到任何影响;它只是方法的选择。你知道吗
相关问题 更多 >
编程相关推荐