相关疑难解决方法(0)

subprocess.Popen():OSError:[Errno 8] python中的exec格式错误?

昨天,我编写并运行了一个python script,它执行一个shellusing subprocess.Popen(command.split())where命令是字符串,它构成了.sh脚本及其参数.这个脚本工作正常,直到昨天.今天,我运行相同的脚本,现在我不断遇到这个错误.

p=subprocess.Popen(shell_command.split())
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
Run Code Online (Sandbox Code Playgroud)

我知道在提出这个问题之前有过类似的问题,但在我的情况下,我尝试了一切不能解决我目的的问题.使用shell=True不起作用,因为我的shell脚本调用另一个shell脚本,在此脚本之前必须设置一些环境才能运行该脚本.我严重陷入困境.我只是重启我的系统一次.我在用ubuntu 12.04

编辑:

 import subprocess
 import os
 import sys

 arg1=sys.argv[1]
 arg2=sys.argve[2]

 shell_command = 'my_path/my_shell.sh ' + arg1 + ' '+ arg2
 P = subprocess.Popen(shell_command.split())
 P.wait()
Run Code Online (Sandbox Code Playgroud)

my_shell.sh:

  arg1=$1
  arg2=$2

  cd $TOP
  setup the environment and run shell script
  build the kernel ...
  execute shell command .....
Run Code Online (Sandbox Code Playgroud)

python linux shell

36
推荐指数
3
解决办法
5万
查看次数

如何执行程序或批处理文件?

我已经安装了PyCharm以在Windows 10上使用Python语言。

我正在尝试从 PyCharm 中的 Linux 命令执行命令,我使用了以下代码:

import subprocess
subprocess.run("cat",shell=True,text=True)
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

'cat' 不是内部或外部命令,也不是可运行的程序或批处理文件。

我想执行多个命令,例如这个示例,但所有命令都会引发相同的错误。如何解决这个问题?

python command-line pycharm windows-10

7
推荐指数
1
解决办法
245
查看次数

如何正确导入鼠尾草?

编辑:我需要澄清一下,我想将鼠尾草作为库导入,以在鼠尾草外壳的Python脚本之外使用,因为我需要它在Django上作为服务器运行。

我必须从源头编译贤哲吗?

我一直在尝试将sage用于我的python脚本。

代码如下:

#!/usr/bin/env sage -python
from django.shortcuts import render
from django.http import HttpResponse
import sys
from django.http import HttpRequest
from django.template import RequestContext, loaders
from sage.all import *

def index(request):

    querystring = request.GET.get('querystring')

    return HttpResponse(querystring)
# Create your views here.
Run Code Online (Sandbox Code Playgroud)

但是我遇到一个错误:没有名为sage.all的模块

我没有遇到麻烦

#!/usr/bin/env sage -python
import sys
from sage.all import *
var('x')
print integrate(x,x)
print latex(integrate(sin(x),x))
Run Code Online (Sandbox Code Playgroud)

从命令行 ./sage -python /path/to/script.py

所以我不明白为什么我不能导入鼠尾草...

目录“ sage”位于python路径中,位于我要在其中使用的views.py文件旁边,我尝试将其放置在各个不同的位置,或将其附加到sys.path中,以徒劳无功。非常感谢任何帮助,这是一个非常重要的项目。我正在尝试将Sage导入Django项目。

编辑:我不使用./sage -python运行第二个,而是在Django localhost服务器上将它作为views.py运行。

python django import module sage

5
推荐指数
1
解决办法
4910
查看次数

用Django运行bash脚本

我是django的新手.当我在html中按下一个按钮时,我需要运行一个bash脚本,我需要使用Django Framework,因为我用它来构建我的web.如果有人能帮助我,我将不胜感激

编辑:我已添加了我的模板和我的观点以获得更多帮助.在'nuevaCancion'模板中,我使用了2个视图.

<body>
	
	{% block cabecera %}
	<br><br><br>
	<center>
	<h2> <kbd>Nueva Cancion</kbd> </h2>
	</center>
	{% endblock %}
	
	{% block contenido %}

		<br><br>
		<div class="container">
    		<form id='formulario' method='post' {% if formulario.is_multipart %} enctype="multipart/form-data" {% endif %} action=''>
				{% csrf_token %}
    			<center>
				<table>{{formulario}}</table>
        		<br><br>
        		<p><input type='submit' class="btn btn-success btn-lg" value='Añadir'/>
				 <a href="/ListadoCanciones/" type="input" class="btn btn-danger btn-lg">Cancelar</a></p>
				</center>
      	</form>
    	<br>
	</div>
	<center>
		<form action="" method="POST">
    		{% csrf_token %}
    		<button type="submit" class="btn btn-warning btn-lg">Call</button>
		</form>
	</center>
	{% endblock %}

</body>
Run Code Online (Sandbox Code Playgroud)

Views.py

def index(request): …
Run Code Online (Sandbox Code Playgroud)

html python django bash shell

4
推荐指数
1
解决办法
3755
查看次数

标签 统计

python ×4

django ×2

shell ×2

bash ×1

command-line ×1

html ×1

import ×1

linux ×1

module ×1

pycharm ×1

sage ×1

windows-10 ×1