Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python文件中运行一个python命令,并读取输出_Python_Python 3.x_Tensorflow_Spyder - Fatal编程技术网

在python文件中运行一个python命令,并读取输出

在python文件中运行一个python命令,并读取输出,python,python-3.x,tensorflow,spyder,Python,Python 3.x,Tensorflow,Spyder,我是python新手,正在尝试将此命令的输出转换为字符串 C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py --temperature 0.8 --top_k 40 --model_name run1-- nsamples 1 --length 100 下面是我用“>>>>”尝试过的东西,表示每个问题 有没有更好的方法我不知道 Python3.7 spyder 预期执行 C:\GPT2\gpt-2-fine

我是python新手,正在尝试将此命令的输出转换为字符串

C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py --temperature 0.8 --top_k 40 --model_name run1-- nsamples  1 --length 100
下面是我用“>>>>”尝试过的东西,表示每个问题

有没有更好的方法我不知道

Python3.7 spyder

预期执行

C:\GPT2\gpt-2-finetuning>C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py --temperature 0.8 --top_k 40 --model_name run1 --nsamples  1 --length 100
2020-05-07 23:14:59.846175: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2020-05-07 23:14:59.852383: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:147: The name tf.AUTO_REUSE is deprecated. Please use tf.compat.v1.AUTO_REUSE instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py:52: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2020-05-07 23:15:02.748274: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-05-07 23:15:02.754792: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: UNKNOWN ERROR (303)
2020-05-07 23:15:02.769396: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-[redacted]
2020-05-07 23:15:02.775857: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-6H0CO8Q
2020-05-07 23:15:02.782411: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py:54: The name tf.set_random_seed is deprecated. Please use tf.compat.v1.set_random_seed instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:148: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:152: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:36: The name tf.rsqrt is deprecated. Please use tf.math.rsqrt instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:166: The name tf.add_to_collection is deprecated. Please use tf.compat.v1.add_to_collection instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\sample.py:65: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.cast` instead.
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\sample.py:16: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\sample.py:70: multinomial (from tensorflow.python.ops.random_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.random.categorical` instead.
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py:63: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

======================================== SAMPLE 1 ========================================
<user>dont be like that
<user>I dont want to be a kid anymore
(ect.)
C:\GPT2\gpt-2-finetunning>C:\GPT2\gpt-2-finetunning\src\generate\u无条件\u samples.py--温度0.8--顶部\u k 40--型号\u名称run1--样本1--长度100
2020-05-07 23:14:59.846175:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库“cudart64_100.dll”;错误:找不到cudart64_100.dll
2020-05-07 23:14:59.852383:I tensorflow/stream_executor/cuda/cudart_stub.cc:29]如果您的机器上没有设置GPU,请忽略上面的cudart dler错误。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\model.py:147:不推荐使用tf.AUTO\u重用的名称。请改用tf.compat.v1.AUTO_重用。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\generate\u无条件\u samples.py:52:名称tf.Session已弃用。请改用tf.compat.v1.Session。
2020-05-07 23:15:02.748274:W tensorflow/stream_executor/platform/default/dso_loader.cc:55]无法加载动态库“nvcuda.dll”;错误:未找到nvcuda.dll
2020-05-07 23:15:02.754792:E tensorflow/stream_executor/cuda/cuda_driver.cc:318]调用cuInit失败:未知错误(303)
2020-05-07 23:15:02.769396:I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169]检索主机的cuda诊断信息:桌面-[编辑]
2020-05-07 23:15:02.775857:I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176]主机名:DESKTOP-6H0CO8Q
2020-05-07 23:15:02.782411:I tensorflow/core/platform/cpu\u feature\u guard.cc:142]您的cpu支持该tensorflow二进制文件未编译为使用的指令:AVX2
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\generate\u无条件\u samples.py:54:不推荐使用名称tf.set\u random\u seed。请改用tf.compat.v1.set_random_seed。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\model.py:148:不推荐使用名称tf.variable\u scope。请改用tf.compat.v1.variable\u作用域。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\model.py:152:不推荐使用名称tf.get\u变量。请改用tf.compat.v1.get_变量。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\model.py:36:不推荐使用名称tf.rsqrt。请改用tf.math.rsqrt。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\model.py:166:不推荐使用名称tf.add\u to\u集合。请改用tf.compat.v1.add_到_集合。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\sample.py:65:to_float(From tensorflow.python.ops.math_ops)已弃用,将在未来版本中删除。
更新说明:
改用'tf.cast'。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\sample.py:16:where(From tensorflow.python.ops.array\u ops)已被弃用,并将在将来的版本中删除。
更新说明:
在2.0中使用tf.where,它与np.where具有相同的广播规则
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\sample.py:70:multinomial(From tensorflow.python.ops.random_ops)已弃用,将在未来版本中删除。
更新说明:
改为使用'tf.random.category'。
警告:tensorflow:From C:\GPT2\gpt-2-finetunning\src\generate\u无条件\u samples.py:63:不推荐使用名称tf.train.Saver。请改用tf.compat.v1.train.Saver。
=============================================================样本1========================================
别那样
我不想再当孩子了
(等)

也许可以尝试调用python可执行文件(确保“python.exe”位于路径中或指定完整路径):

参数中也有一些输入错误(run1后面没有空格,--nsamples后面有两个空格)。您可以始终将参数列表传递给Popen,以便不必管理此参数:

from subprocess import Popen
p = Popen(["python", "C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py", "--temperature",  "0.8", "--top_k", "40", "--model_name", "run1", "--nsamples", "1", "--length", "100"])
stdout, stderr = p.communicate()

谢谢你的回复!不幸的是,仍然没有存储到stderr或stdout的值,并且代码似乎没有运行,因为它通常是一个非常CPU密集的进程,并且没有检测到CPU使用率的增加。
text = os.popen('cat C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py --temperature 0.8 --top_k 40 --model_name run1 --nsamples  1 --length 100').read()

>>>(doesnt run it)
import importlib.util
spec = importlib.util.spec_from_file_location("generate_unconditional_samples", "C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py")
foo = importlib.util.module_from_spec(spec)
spec.loader.exec_module(foo)
foo.MyClass()

>>>ModuleNotFoundError: No module named 'fire'(fire is the first import call in the module also no augments)
command='cmd /C C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py --temperature 0.8 --top_k 40 --model_name run1 --nsamples  1 --length 100'
proc=Popen(command,creationflags=CREATE_NEW_CONSOLE,stdout=PIPE)
output=proc.communicate()[0]
print (output)

>>>b''(thats the full output)
C:\GPT2\gpt-2-finetuning>C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py --temperature 0.8 --top_k 40 --model_name run1 --nsamples  1 --length 100
2020-05-07 23:14:59.846175: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_100.dll'; dlerror: cudart64_100.dll not found
2020-05-07 23:14:59.852383: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:147: The name tf.AUTO_REUSE is deprecated. Please use tf.compat.v1.AUTO_REUSE instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py:52: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2020-05-07 23:15:02.748274: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-05-07 23:15:02.754792: E tensorflow/stream_executor/cuda/cuda_driver.cc:318] failed call to cuInit: UNKNOWN ERROR (303)
2020-05-07 23:15:02.769396: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: DESKTOP-[redacted]
2020-05-07 23:15:02.775857: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: DESKTOP-6H0CO8Q
2020-05-07 23:15:02.782411: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py:54: The name tf.set_random_seed is deprecated. Please use tf.compat.v1.set_random_seed instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:148: The name tf.variable_scope is deprecated. Please use tf.compat.v1.variable_scope instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:152: The name tf.get_variable is deprecated. Please use tf.compat.v1.get_variable instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:36: The name tf.rsqrt is deprecated. Please use tf.math.rsqrt instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\model.py:166: The name tf.add_to_collection is deprecated. Please use tf.compat.v1.add_to_collection instead.

WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\sample.py:65: to_float (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.cast` instead.
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\sample.py:16: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0, which has the same broadcast rule as np.where
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\sample.py:70: multinomial (from tensorflow.python.ops.random_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.random.categorical` instead.
WARNING:tensorflow:From C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py:63: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

======================================== SAMPLE 1 ========================================
<user>dont be like that
<user>I dont want to be a kid anymore
(ect.)
from subprocess import Popen
p = Popen("python C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py --temperature 0.8 --top_k 40 --model_name run1 --nsamples 1 --length 100")
stdout, stderr = p.communicate()
from subprocess import Popen
p = Popen(["python", "C:\GPT2\gpt-2-finetuning\src\generate_unconditional_samples.py", "--temperature",  "0.8", "--top_k", "40", "--model_name", "run1", "--nsamples", "1", "--length", "100"])
stdout, stderr = p.communicate()