简体   繁体   English

SyntaxError:无效语法:python -c “import numpy”

[英]SyntaxError: invalid syntax: python -c “import numpy”

I have a sample.py python file, which contains this line:我有一个sample.py python 文件,其中包含以下行:

python -c "import numpy"

Run Command:运行命令:

$ python sample.py

When executed, the script got the error:执行时,脚本出现错误:

SyntaxError: invalid syntax SyntaxError:无效的语法

Can anyone help me what is the issue with this line?谁能帮我这条线有什么问题?

The content is not python, it's a command.内容不是 python,是命令。

The content of sample.py should be just sample.py 的内容应该只是

import numpy

python -c... calls python from a shell, and executes -c 's argument by python. python -c...从 shell 调用 python,并执行-c的参数 Z23EEEB4347BDD7556BFC6B7EE9 If you want that in a script, use a shell script, not a python script.如果您想在脚本中使用它,请使用 shell 脚本,而不是 python 脚本。 Alternatively, if you're running it with python anyway, drop the python -c , and just keep the python code ( import numpy ).或者,如果您仍然使用python运行它,请删除python -c ,并保留 python 代码( import numpy

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

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