docker容器中执行pip安装命令报Can‘t start new thread错误解决方法

报错细节:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "<stdin>", line 2, in <dictcomp>
  File "/usr/lib64/python3.8/concurrent/futures/thread.py", line 188, in submit
    self._adjust_thread_count()
  File "/usr/lib64/python3.8/concurrent/futures/thread.py", line 213, in _adjust_thread_count
    t.start()
  File "/usr/lib64/python3.8/threading.py", line 852, in start
    _start_new_thread(self._bootstrap, ())
RuntimeError: can't start new thread

错误原因:docker版本过低(version 20.x)而容器对应的基础镜像版本过高,如Ubuntu22.04、Debian12等,执行程序时程序无法多线程执行。可参考:

This is because the default seccomp profile of Docker 20.10.9 is not adjusted to support the clone() syscall wrapper of glibc 2.34 adopted in Ubuntu 21.10 and Fedora 35.

 解决方法:

1、拉取低版本的镜像(Ubuntu20.04及以下版本、Debian11及以下版本),使用新镜像重新运行封装容器(推荐:不会影响已有的docker镜像与容器),如:

# 原始的高版本镜像
docker pull bitnami/pytorch:latest
docker pull bitnami/pytorch:2.2.2-debian-12-r0

# 新拉取的低版本镜像
docker pull bitnami/pytorch:2.0.0-debian-11-r0

2、卸载旧版本的docker,安装/升级docker至新版本(version 21.x以上),重新运行容器(不推荐:新版本安装过程时间长且容易带来其它问题,可能影响已有的docker镜像与容器);

sudo apt-get upgrade docker-ce

3、安装时,去除进度条显示(不推荐:去除进度条显示(关闭了进度条显示线程)只是保证pip在安装时仅有一个安装线程在执行,当再执行其它多线程程序时还会报其它错误)

# 一次性操作
pip install --progress-bar off opencv-python

# 永久操作
pip config --user set global.progress_bar off

参考博客:在docker中运行 pip 报错 Can‘t start new thread_docker can't start new thread-CSDN博客

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
回答: 在Docker容器,如果你遇到了pip源的问题,可以尝试以下解决步骤。首先,你可以尝试更换镜像源来解决问题。使用"-i"参数指定一个可用的镜像源,例如"pip install -i https://pypi.tuna.tsinghua.edu.cn/simple package_name"。如果更换镜像源后仍然出现问题,你可以尝试修改网卡设置。通过找到文件位置并修改网卡设置,可以禁用Network Manager的管理,这样可能会解决pip源的问题。最后,你还可以参考引用\[1\]提供的链接,该链接提供了一些关于在Docker容器安装pip软件包时遇到问题的解决方案。 #### 引用[.reference_title] - *1* *3* [无法在使用docker容器安装pip包](https://blog.csdn.net/shuaijieer/article/details/111085718)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [在linux docker 容器安装pip install yaml 错](https://blog.csdn.net/m0_68021259/article/details/130911288)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值