直接访问py文件方式

以下黑体字为正确的代码,未加粗的为错误的尝试。(注意空格"."之类的不同)

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

-bash: /Users/apple/Desktop/python/test.py: Permission denied (无权限

appledeMacBook:~ JEZAU$ chmod a+x ./test.py

chmod: ./test.py: No such file or directory

要先cd进入其上一级目录才可以用 ./进入 

cd .. 进入上一级文件夹

appledeMacBook:~ JEZAU$ chmod a+x ./test

chmod: ./test: No such file or directory

appledeMacBook:~ JEZAU$ chmod a+x ./Users/apple/Desktop/python/test.py

chmod: ./Users/apple/Desktop/python/test.py: No such file or directory

appledeMacBook:~ JEZAU$ chmod a+x/Users/apple/Desktop/python/test.py (可执行程序

可以 chmod a+x ./文件夹路径 这样整个文件夹里的py文件就可以直接./hh.py打开了

(苹果里用777不行,得a+x)

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

/Users/apple/Desktop/python/test.py: line 1: syntax error near unexpected token `"hello"'

/Users/apple/Desktop/python/test.py: line 1: `print("hello")'

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

/Users/apple/Desktop/python/test.py: line 1: 100+200: command not found

在py文件前加入#!/usr/local/Cellar/python3/3.6.1/bin/python3

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

其中的内容需要print才可以显示

appledeMacBook:~ JEZAU$ /Users/apple/Desktop/python/test.py

hello,world

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容