I am looking to run a file I created in python from a matlab script. I have checked that my python file works if I run it from the python interface. However I have not been able to get my python to run from matlab. The following is the code situation I am in.
我希望运行一个用python从matlab脚本创建的文件。我已经检查了我的python文件是否在python接口上运行。但是我还没能让我的python从matlab中运行。下面是我所处的代码情况。
In matlab., I have the following code:(My file name is pgcode.py) ! python pgcode.py
and interchangeably I have use this code as well: system('python pgcode.py')
在matlab。,我有以下代码:(我的文件名是pgcode.py) !python pgcode。我也用过这段代码:system('python pgcode.py')
The error that results in matlab is: "python: can't open file 'pgcode.py': [Errno 2] No such file or directory"
matlab中出现的错误是:“python:无法打开文件的pgcode”。没有这样的文件或目录"
I have set my PATH directory and I really think this is an issue with setting the path so that I can find the file I have created but I haven't been able to figure out how to do this. I am using windows and Python 2.7.5. Any help is much appreciated. Thanks in advance!
我已经设置了路径目录,我真的认为这是设置路径的问题,这样我就可以找到我创建的文件,但是我还没能找到怎么做。我使用的是windows和Python 2.7.5。非常感谢您的帮助。提前谢谢!
2 个解决方案
#1
1
There might be another way to do this, but here are two options.
可能还有另外一种方法,但这里有两个选项。
First replace system('python pgcode.py')
with system('pgcode.py')
. Make sure that pgcode.py
has execute permissions and in on your PATH
. If you're using a unix/linux/mac type system, make sure pgcode.py
has #!/usr/bin/env python
as the first line, that's called a shebang.
首先用system('pgcode.py')替换system('pgcode.py')。确保pgcode。py具有执行权限,并且在您的路径上。如果您正在使用unix/linux/mac类型的系统,请确保使用pgcode。py # !/usr/bin/env python作为第一行,这叫做shebang。
Option two, is to use the full path when you call system(pathon /full/path/to/pgcode.py
).
选项二,是在调用system(pathon /full/path/to/pgcode.py)时使用完整路径。
Hope that helps.
希望有帮助。
#2
1
Your $PATH should control where python comes from, but I don't believe it will control where your pgcode.py comes from - at least, not in the way you're using it now.
您的$PATH应该控制python来自哪里,但是我不相信它会控制您的pgcode。py来自-至少不是你现在使用它的方式。
You might want to either use a #!/usr/bin/env python and make your script executable, or be very mindful of what directory you're in when you try to python pgcode.py (you can prepend "pwd;" to your python command to see), or specify a full path to pgcode.py.
您可能需要使用#!/usr/bin/env python并使您的脚本可执行,或者在尝试python pgcode时非常注意所处的目录。py(您可以将“pwd”添加到您的python命令中查看),或者指定一个完整的pgcode.py路径。
HTH
HTH
#1
1
There might be another way to do this, but here are two options.
可能还有另外一种方法,但这里有两个选项。
First replace system('python pgcode.py')
with system('pgcode.py')
. Make sure that pgcode.py
has execute permissions and in on your PATH
. If you're using a unix/linux/mac type system, make sure pgcode.py
has #!/usr/bin/env python
as the first line, that's called a shebang.
首先用system('pgcode.py')替换system('pgcode.py')。确保pgcode。py具有执行权限,并且在您的路径上。如果您正在使用unix/linux/mac类型的系统,请确保使用pgcode。py # !/usr/bin/env python作为第一行,这叫做shebang。
Option two, is to use the full path when you call system(pathon /full/path/to/pgcode.py
).
选项二,是在调用system(pathon /full/path/to/pgcode.py)时使用完整路径。
Hope that helps.
希望有帮助。
#2
1
Your $PATH should control where python comes from, but I don't believe it will control where your pgcode.py comes from - at least, not in the way you're using it now.
您的$PATH应该控制python来自哪里,但是我不相信它会控制您的pgcode。py来自-至少不是你现在使用它的方式。
You might want to either use a #!/usr/bin/env python and make your script executable, or be very mindful of what directory you're in when you try to python pgcode.py (you can prepend "pwd;" to your python command to see), or specify a full path to pgcode.py.
您可能需要使用#!/usr/bin/env python并使您的脚本可执行,或者在尝试python pgcode时非常注意所处的目录。py(您可以将“pwd”添加到您的python命令中查看),或者指定一个完整的pgcode.py路径。
HTH
HTH