如何在Docker容器中将python2别名为python3? [英] How do I alias python2 to python3 in a docker container?

查看:74
本文介绍了如何在Docker容器中将python2别名为python3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将docker容器中的默认python设置为python3,并在dockerfile中设置了别名.当我打开.bashrc文件时,它们就会出现.据我所知,它应该可以工作,但是默认的python版本仍然是2.7.如果我运行哪个python,它将仍然指向usr/bin/python而不是python3.点子一样.谁能告诉我问题是什么?这是我用来别名的命令:

I am trying to set the default python in my docker container to be python3 and have set the aliases in the dockerfile. When I open the .bashrc file, they show up. As far as I can tell, it should work but the default python version is still 2.7. if I run which python, it will still point to usr/bin/python rather than python3. Same with pip. Can anyone tell me what the problem is? Here is the command I'm using to alias:

   RUN \
   echo 'alias python="/usr/bin/python3"' >> /root/.bashrc && \
   echo 'alias pip="/usr/bin/pip3"' >> /root/.bashrc

这看起来正确吗?我正在使用ubuntu 17.10

Does this look right? I am using ubuntu 17.10

推荐答案

您尝试为python bin创建符号链接

You try to create a symlink for python bin

RUN ln -s /usr/bin/python3 /usr/bin/python & \
    ln -s /usr/bin/pip3 /usr/bin/pip

另一种选择是使用 update-alternatives 进行更多访问此网站

other option is use update-alternatives for more visit this site

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3

另一种选择是在更新后尝试获取bashrc文件的源代码

and another option is trying source the bashrc file after updating

RUN \
   echo 'alias python="/usr/bin/python3"' >> /root/.bashrc && \
   echo 'alias pip="/usr/bin/pip3"' >> /root/.bashrc && \
   source /root/.bashrc


我建议在 Docker Hub

提示:使用 anaconda conda 来管理您的python版本(

Tip: use anaconda or conda for managing your python versions (conda site)

这篇关于如何在Docker容器中将python2别名为python3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆