Python 3.x 在pyenv中将matplotrust与python3解释器一起使用 我的环境 Ubuntu 18.04 Python 3.7.3(~/.pyenv/shimmes/Python) 锈蚀(货物1.36.0) 问题

Python 3.x 在pyenv中将matplotrust与python3解释器一起使用 我的环境 Ubuntu 18.04 Python 3.7.3(~/.pyenv/shimmes/Python) 锈蚀(货物1.36.0) 问题,python-3.x,rust,Python 3.x,Rust,我是Rust语言的初学者,尝试使用matplotrustcrate绘制绘图。我编写了如下代码: 外部板条箱锈迹; 使用matplotrust:{line_plot,Figure}; fn main(){ //在文本文件中加载值 让result=std::fs::读取字符串(“test.txt”); 让内容=匹配结果{ Ok(内容)=>内容, Err(error)=>{ 死机!(“无法读取文件:{}”,错误); } }; 让行数组:Vec=content.trim().split(“\n”).co

我是Rust语言的初学者,尝试使用
matplotrust
crate绘制绘图。我编写了如下代码:

外部板条箱锈迹;
使用matplotrust:{line_plot,Figure};
fn main(){
//在文本文件中加载值
让result=std::fs::读取字符串(“test.txt”);
让内容=匹配结果{
Ok(内容)=>内容,
Err(error)=>{
死机!(“无法读取文件:{}”,错误);
}
};
让行数组:Vec=content.trim().split(“\n”).collect();
//在向量x和y中插入值
让mut x:Vec=Vec::new();
让mut y:Vec=Vec::new();
对于“行中的行”\u数组{
let pair:Vec=line.trim().split(“”.collect();
x、 推送(对[0].parse().unwrap());
y、 推送(对[1].parse().unwrap());
}
//用y和x作图
设lp=直线图::(x,y,无);
让mut figure=figure::new();
图.添加图(lp.clone());
图.添加图(lp.clone());
打印!(“{:?}”,figure.save(“./test.png”,None));
}
我可以构建这段代码,但在运行时发生了一个错误

线程'main'在'python binary not found at/usr/local/bin/python3:Os{code:2,kind:NotFound,消息:“没有这样的文件或目录“}”,src/libcore/result.rs:999:5
注意:使用'RUST_BACKTRACE=1'环境变量运行以显示回溯。
它说python路径是错误的。但在我的例子中,我使用pyenv,不在这个目录中安装python3

如何解决这个问题

我试过的 我试图在
/usr/local/bin
中用
apt install
安装python3,但是shell说python3已经用pyenv安装了

@Jmb的评论修复了用户的问题。写一个答案只是为了说明在这种情况下如何继续

matplotlib
Rust板条箱文档不是很好(无)。在这种情况下,您必须检查以下方法:

pub-fn-save(&mut-self,输出:&str,路径:Option)->(字符串,字符串,字符串){
self.script+=&format!('plt.savefig('{}')\n',输出);
//创建一个临时文件
让mut tmpfile:NamedTempFile=tempfile::NamedTempFile::new().unwrap();
tmpfile.write_all(self.script.as_bytes());
让python_path=匹配路径{
一些=>s,
无=>“/usr/local/bin/python3”
};
元数据(python_path).expect(“在/usr/local/bin/python3中找不到python二进制文件”);
让mut echo_hello=Command::new(python_路径);
echo_hello.arg(tmpfile.path());
echo_hello.output().expect(“未能执行进程”);
返回(self.script.to_string()、output.to_string()、tmpfile.path()、to_str()、unwrap()、to_string());
}
重要的是这一点:

让python_path=匹配路径{
一些=>s,
无=>“/usr/local/bin/python3”
};
您调用了
figure.save(“./test.png”,None)
->
/usr/local/bin/python3
。正如@Jmb所指出的,您可以通过
figure.save(“./test.png”,Some(“/path/to/python3”)
指定python3解释器路径以使其工作

@Jmb的评论修复了用户的问题。写一个答案只是为了说明在这种情况下如何继续

matplotlib
Rust板条箱文档不是很好(无)。在这种情况下,您必须检查以下方法:

pub-fn-save(&mut-self,输出:&str,路径:Option)->(字符串,字符串,字符串){
self.script+=&format!('plt.savefig('{}')\n',输出);
//创建一个临时文件
让mut tmpfile:NamedTempFile=tempfile::NamedTempFile::new().unwrap();
tmpfile.write_all(self.script.as_bytes());
让python_path=匹配路径{
一些=>s,
无=>“/usr/local/bin/python3”
};
元数据(python_path).expect(“在/usr/local/bin/python3中找不到python二进制文件”);
让mut echo_hello=Command::new(python_路径);
echo_hello.arg(tmpfile.path());
echo_hello.output().expect(“未能执行进程”);
返回(self.script.to_string()、output.to_string()、tmpfile.path()、to_str()、unwrap()、to_string());
}
重要的是这一点:

让python_path=匹配路径{
一些=>s,
无=>“/usr/local/bin/python3”
};
您调用了
figure.save(“./test.png”,None)
->
/usr/local/bin/python3
。正如@Jmb所指出的,您可以通过
figure.save(“/test.png”,Some(“/path/to/python3”)
指定python3解释器路径以使其工作。

尝试
figure.save(“/test.png”,Some(“/path/to/Python”)
尝试
figure.save(“/test.png”,Some(/path/to/Python”))