You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行plotCoverage.py遇pysam模块缺失,安装pysam时出现os/rand.c文件不存在错误的解决求助

Fixing pysam Installation Error: htslib/hts_os.c:30:21: fatal error: os/rand.c

I’ve run into this exact compilation issue with pysam before, and it’s usually tied to missing system dependencies or quirks in how pip handles htslib builds under the hood. Here are a few tried-and-true fixes to get you past this:

1. Install all required system dependencies for htslib

liblzma-dev is one piece of the puzzle, but htslib (the core library pysam relies on) needs several other dependencies to compile successfully. Run this command to install the full set:

sudo apt-get update && sudo apt-get install libbz2-dev libcurl4-openssl-dev libssl-dev zlib1g-dev python3.9-dev
  • python3.9-dev ensures critical Python header files (like Python.h) are available, which also addresses your earlier deeptoolsintervals error.
  • The other libraries handle compression (bz2, zlib, lzma) and network/crypto functionality htslib depends on.

2. Use Conda to install pysam (avoids compilation entirely)

If compiling from source keeps failing, using Conda’s pre-built pysam package is often the easiest workaround. Conda handles all dependency conflicts and delivers pre-compiled packages tailored to your system:

# If you don’t have Conda set up, install Miniconda first, then activate your environment:
conda activate your_working_env
conda install -c bioconda pysam

Bioconda is the standard channel for bioinformatics tools like pysam, so this should pull in a fully functional version without any build errors.

3. Force pip to use system-wide htslib (bypass isolated builds)

If you must use pip, try disabling its build isolation feature—this makes pip use your system’s pre-installed htslib instead of trying to compile it from scratch. First, install htslib system-wide:

sudo apt-get install htslib-dev

Then install pysam with this flag:

pip3.9 install pysam --no-build-isolation

This tells pip to skip downloading and building its own copy of htslib, relying on the system’s pre-configured version instead.

4. Verify your Python environment alignment

Double-check that you’re installing pysam into the same Python 3.9 environment you’re using to run plotCoverage.py. It’s easy to accidentally install packages into a different Python version without noticing. Run these commands to confirm alignment:

which python3.9
which pip3.9

If the paths don’t match, use python3.9 -m pip install pysam instead of pip3.9—this guarantees you’re targeting the correct Python instance.


内容的提问来源于stack exchange,提问作者xyz0o

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 10:17:31