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

如何让make install调用conda环境安装HaploStrips并解决环境创建异常?

解决HaploStrips安装时的Python环境依赖问题

我尝试安装HaploStrips,该工具要求Python 2.7、pip及若干其他依赖库。作者建议用conda create -n haplostrips python=2.7 pandas=0.22 pysam创建Anaconda环境,激活后执行安装。但按此操作后,安装程序仍找不到pandas或pysam,且默认使用系统的Python 3.8而非conda环境里的Python 2.7。

需要解决两个问题:

  • 如何让make install使用Anaconda提供的可执行文件?
  • 是否有更好的方式确保工具使用Python 2.7及对应依赖?

执行conda create --name haplostripsb python=2.7的输出

>>> conda create --name haplostripsb python=2.7
Collecting package metadata (current_repodata.json): failed
WARNING conda.exceptions:print_unexpected_error_report(1216): KeyError('pkgs_dirs')
Traceback (most recent call last):
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/exceptions.py", line 1082, in __call__
return func(*args, **kwargs)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/main.py", line 87, in _main
exit_code = do_call(args, p)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/conda_argparse.py", line 84, in do_call
return getattr(module, func_name)(args, parser)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/main_create.py", line 41, in execute
install(args, parser, 'create')
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/install.py", line 260, in install
unlink_link_transaction = solver.solve_for_transaction(
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 152, in solve_for_transaction
unlink_precs, link_precs = self.solve_for_diff(update_modifier, deps_modifier,
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 195, in solve_for_diff
final_precs = self.solve_final_state(update_modifier, deps_modifier, prune, ignore_pinned,
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 300, in solve_final_state
ssc = self._collect_all_metadata(ssc)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/common/io.py", line 88, in decorated
return f(*args, **kwds)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 435, in _collect_all_metadata
_supplement_index_with_system(virtual_pkg_index)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/index.py", line 164, in _supplement_index_with_system
dist_name, dist_version = context.os_distribution_name_version
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/auxlib/decorators.py", line 268, in new_fget
cache[inner_attname] = func(self)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/base/context.py", line 863, in os_distribution_name_version
from conda._vendor.distro import id, version
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/_vendor/distro.py", line 1084, in <module>
_distro = LinuxDistribution()
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/_vendor/distro.py", line 599, in __init__
self._lsb_release_info = self._get_lsb_release_info() \
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/_vendor/distro.py", line 943, in _get_lsb_release_info
raise subprocess.CalledProcessError(code, cmd, stdout, stderr)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/exceptions.py", line 1214, in print_unexpected_error_report
message_builder.append(get_main_info_str(error_report['conda_info']))
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/main_info.py", line 237, in get_main_info_str
info_dict['_' + key] = ('\n' + 26 * ' ').join(info_dict[key])
KeyError: 'pkgs_dirs'
# >>>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/exceptions.py", line 1082, in __call__
return func(*args, **kwargs)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/main.py", line 87, in _main
exit_code = do_call(args, p)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/conda_argparse.py", line 84, in do_call
return getattr(module, func_name)(args, parser)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/main_create.py", line 41, in execute
install(args, parser, 'create')
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/cli/install.py", line 260, in install
unlink_link_transaction = solver.solve_for_transaction(
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 152, in solve_for_transaction
unlink_precs, link_precs = self.solve_for_diff(update_modifier, deps_modifier,
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 195, in solve_for_diff
final_precs = self.solve_final_state(update_modifier, deps_modifier, prune, ignore_pinned,
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 300, in solve_final_state
ssc = self._collect_all_metadata(ssc)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/common/io.py", line 88, in decorated
return f(*args, **kwds)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/solve.py", line 435, in _collect_all_metadata
_supplement_index_with_system(virtual_pkg_index)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/core/index.py", line 164, in _supplement_index_with_system
dist_name, dist_version = context.os_distribution_name_version
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/auxlib/decorators.py", line 268, in new_fget
cache[inner_attname] = func(self)
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/base/context.py", line 863, in os_distribution_name_version
from conda._vendor.distro import id, version
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/_vendor/distro.py", line 1084, in <module>
_distro = LinuxDistribution()
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/_vendor/distro.py", line 599, in __init__
self._lsb_release_info = self._get_lsb_release_info() \
File "/home/muthur/anaconda3/lib/python3.8/site-packages/conda/_vendor/distro.py", line 943, in _get_lsb_release_info
raise subprocess.CalledProcessError(code, cmd, stdout, stderr)
subprocess.CalledProcessError: Command 'lsb_release -a' returned non-zero exit status 1.
`$ /home/muthur/anaconda3/bin/conda create --name haplostripsb python=2.7`
environment variables:
conda info could not be constructed.
KeyError('pkgs_dirs')
An unexpected error has occurred. Conda has prepared the above report.

执行lsb_release -a的输出

>>> lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

解决步骤

1. 修复conda的lsb_release报错

conda创建环境失败是因为lsb_release -a返回非零状态码(尽管输出正常),可通过以下方式解决:

  • 临时设置环境变量跳过检测:
    export CONDA_DISTRIBUTION_NAME="Ubuntu" CONDA_DISTRIBUTION_VERSION="20.04"
    
    之后再重新执行conda创建环境命令。
  • 修改conda配置:
    conda config --set restore_free_channel true
    
  • 修改/usr/bin/lsb_release脚本:找到脚本末尾的exit 1,改为exit 0。

2. 正确创建并激活conda环境

修复conda后,重新创建环境:

conda create -n haplostrips python=2.7 pandas=0.22 pysam

激活环境:

  • 新版conda:conda activate haplostrips
  • 旧版conda:source activate haplostrips

激活后验证环境:

# 确认Python版本为2.7.x
python --version
# 确认依赖已安装
pip list | grep -E "pandas|pysam"

3. 让make install使用conda环境的Python

make install默认调用系统PATH中的Python,可通过两种方式指定:

  • 方式一:确保激活conda环境后,环境的Python路径在PATH最前端,直接执行make install即可。
  • 方式二:修改HaploStrips的Makefile,指定PYTHON变量为conda环境的Python路径,例如:
    PYTHON = /home/muthur/anaconda3/envs/haplostrips/bin/python
    
    保存后再执行make install。

4. 备选方案:使用virtualenv替代conda

如果conda问题难以解决,可直接用virtualenv搭建Python2.7环境:

# 安装依赖
sudo apt install python2.7 python2.7-dev virtualenv
# 创建并激活环境
virtualenv -p /usr/bin/python2.7 haplostrips_env
source haplostrips_env/bin/activate
# 安装工具依赖
pip install pandas==0.22 pysam
# 执行安装
make install

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 23:25:17