![](/img/trans.png)
[英]Jupyter notebook python version different from environment python version
[英]Run a python script in a different environment from a Jupyter Notebook
我有一个在切片器内核上运行的Jupyter Notebook主文件。 它打开切片器并使用户保存标签。 我知道如何在Python 3内核上的PyTorch中运行深度学习模型。 为此,我首先需要将标签转换为所需的tiff格式。
我设法在Spyder中做到了。
import numpy as np
from imageio import imwrite
import os
## define where the masks are saved as a .npy
labelpath="../temp/label.npy" # changed for privacy
## define path where the new masks should be saved as .tiff files
labelpathsave="../temp/" # changed for privacy
## open the object
label=np.load(labelpath)
number_files=np.shape(label)[0]
for i in range(0, number_files):
string="label"+str(i+1)+".tiff"
labelpath=os.path.join(labelpathsave, string)
currentlabel=label[i]
imwrite(labelpath, currentlabel)
上面的方法有效,但是尝试在Jupyter Notebook中执行此python文件。
execfile('../scripts/Maja/transform_label.py') # changed for privacy
我收到“导入错误:没有名为imageio的模块”。
如果它在不同的环境中运行,我如何使其执行“ transform_label.py”?
(我需要在单独的文件中执行此操作,因为无法使PyTorch软件包在Slicer内核上工作)
对于python 2
pip install imageio --user
对于python 3
pip3 install imageio --user
对于Conda环境
conda install -c conda-forge imageio
注意 :必须首先检查Notebook上正在运行哪个版本的python。
安装后 ( 安装包括导入所需的所有必需的库 。)重新运行以上代码!
我认为该脚本无法正常工作,因为找不到imageio模块。 您是否尝试过将imageio保存在一个目录中,而您知道Jupyter笔记本可以加载其他模块吗? 也许仅仅是目录的问题,jupyter笔记本在其中寻找模块。
或者也可能是对于spyder(如果您通过anaconda发行版使用它)已预装了此imageio软件包。 因此,您也可以尝试在jupyter中检查是否已安装软件包。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.