python-3.x - nextflow 没有找到我所有的 python 模块

标签 python-3.x import nextflow

我正在尝试制作一个使用 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-3.x - nextflow 没有找到我所有的 python 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68796059/

相关文章:

python - 临时通配符导入/numpy 公式的可读性

bash - 2 个进程,但在 nextflow 管道中不相关

python - 如何导入 Python lambda 层?

python - 在 Snakemake 工作流程中作为输入的值数组

python - 当使用 tensorflow 和我自己的数据时如何决定批量大小?

arrays - 删除给定数组中所有元素为 "True"的所有子数组

python - 根据列值拆分数据框并导出到不同的 Excel 工作表

javascript - 将 Jquery 中的值列表发送到 flask 模板

objective-c - 基本 Objective-C 导入问题