nextflow 找不到我所有的 python 模块
nextflow does not find all my python modules
我正在尝试制作一个使用 python 脚本的 Nextflow 脚本。我的 python 脚本导入了许多模块,但在 Nextflow python3 中找不到 7 个模块中的两个(cv2 和 matplotlib)并崩溃。如果我直接从 bash 调用脚本,它工作正常。我想避免为 运行 这个脚本创建 docker 图像。
Error executing process > 'grab_images (1)'
Caused by:
Process `grab_images (1)` terminated with an error exit status (1)
Command executed:
python3 --version
echo 'processing image-1.npy'
python3 /home/hq/cv_proj/k_means2.py image-1.npy
Command exit status:
1
Command output:
Python 3.7.3
processing image-1.npy
Command error:
Traceback (most recent call last):
File "/home/hq/cv_proj/k_means2.py", line 5, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
Work dir:
/home/hq/cv_proj/work/7f/b787c62ec420b2b5eb490603ef913f
Tip: you can replicate the issue by changing to the process work dir and entering the command `bash .command.run`
我认为存在路径问题,因为 numpy、sys、re、time 等模块已成功加载。我该如何解决?
提前致谢
更新
为了帮助其他可能在 nextflow 脚本中使用 python 时遇到问题的人...请确保您的 shebang 是正确的。我正在使用
#!/usr/bin/python
而不是
#!/usr/bin/python3
因为我所有的包都是用 pip3 安装的,而且我只使用 python3,所以你需要有正确的 shebang。
最好避免在进程声明中使用脚本的绝对路径。文档的这一部分值得花一些时间阅读:https://www.nextflow.io/docs/latest/sharing.html#manage-dependencies,尤其是关于如何管理第三方脚本的小节:
Any third party script that does not need to be compiled (Bash,
Python, Perl, etc) can be included in the pipeline project repository,
so that they are distributed with it.
Grant the execute permission to these files and copy them into a
folder named bin/ in the root directory of your project repository.
Nextflow will automatically add this folder to the PATH environment
variable, and the scripts will automatically be accessible in your
pipeline without the need to specify an absolute path to invoke them.
那么问题就是如何管理你的Python依赖。您提到 Docker 不是一个选项。 Conda 也不是一个选项吗? Conda 的配置可能类似于:
name: myenv
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- conda-forge::matplotlib-base=3.4.3
- conda-forge::numpy=1.21.2
- conda-forge::opencv=4.5.2
然后,如果上面的内容在名为 environment.yml
的文件中,请使用以下内容创建环境:
conda env create
另请参阅 best practices 使用 Conda。
我正在尝试制作一个使用 python 脚本的 Nextflow 脚本。我的 python 脚本导入了许多模块,但在 Nextflow python3 中找不到 7 个模块中的两个(cv2 和 matplotlib)并崩溃。如果我直接从 bash 调用脚本,它工作正常。我想避免为 运行 这个脚本创建 docker 图像。
Error executing process > 'grab_images (1)'
Caused by:
Process `grab_images (1)` terminated with an error exit status (1)
Command executed:
python3 --version
echo 'processing image-1.npy'
python3 /home/hq/cv_proj/k_means2.py image-1.npy
Command exit status:
1
Command output:
Python 3.7.3
processing image-1.npy
Command error:
Traceback (most recent call last):
File "/home/hq/cv_proj/k_means2.py", line 5, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
Work dir:
/home/hq/cv_proj/work/7f/b787c62ec420b2b5eb490603ef913f
Tip: you can replicate the issue by changing to the process work dir and entering the command `bash .command.run`
我认为存在路径问题,因为 numpy、sys、re、time 等模块已成功加载。我该如何解决?
提前致谢
更新
为了帮助其他可能在 nextflow 脚本中使用 python 时遇到问题的人...请确保您的 shebang 是正确的。我正在使用
#!/usr/bin/python
而不是
#!/usr/bin/python3
因为我所有的包都是用 pip3 安装的,而且我只使用 python3,所以你需要有正确的 shebang。
最好避免在进程声明中使用脚本的绝对路径。文档的这一部分值得花一些时间阅读:https://www.nextflow.io/docs/latest/sharing.html#manage-dependencies,尤其是关于如何管理第三方脚本的小节:
Any third party script that does not need to be compiled (Bash, Python, Perl, etc) can be included in the pipeline project repository, so that they are distributed with it.
Grant the execute permission to these files and copy them into a folder named bin/ in the root directory of your project repository. Nextflow will automatically add this folder to the PATH environment variable, and the scripts will automatically be accessible in your pipeline without the need to specify an absolute path to invoke them.
那么问题就是如何管理你的Python依赖。您提到 Docker 不是一个选项。 Conda 也不是一个选项吗? Conda 的配置可能类似于:
name: myenv
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- conda-forge::matplotlib-base=3.4.3
- conda-forge::numpy=1.21.2
- conda-forge::opencv=4.5.2
然后,如果上面的内容在名为 environment.yml
的文件中,请使用以下内容创建环境:
conda env create
另请参阅 best practices 使用 Conda。