Close Menu
    Trending
    • Revisiting Benchmarking of Tabular Reinforcement Learning Methods
    • Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025
    • Qantas data breach to impact 6 million airline customers
    • He Went From $471K in Debt to Teaching Others How to Succeed
    • An Introduction to Remote Model Context Protocol Servers
    • Blazing-Fast ML Model Serving with FastAPI + Redis (Boost 10x Speed!) | by Sarayavalasaravikiran | AI Simplified in Plain English | Jul, 2025
    • AI Knowledge Bases vs. Traditional Support: Who Wins in 2025?
    • Why Your Finance Team Needs an AI Strategy, Now
    AIBS News
    • Home
    • Artificial Intelligence
    • Machine Learning
    • AI Technology
    • Data Science
    • More
      • Technology
      • Business
    AIBS News
    Home»Machine Learning»Docker Magic: Installing and Managing Multiple Python Versions | by Padmajeet Mhaske | Mar, 2025
    Machine Learning

    Docker Magic: Installing and Managing Multiple Python Versions | by Padmajeet Mhaske | Mar, 2025

    Team_AIBS NewsBy Team_AIBS NewsMarch 5, 2025No Comments3 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    A Dockerfile itself can not immediately comprise a number of Python variations, as every Docker picture is usually primarily based on a single working system surroundings with a single model of Python put in. Nevertheless, you possibly can create a Docker picture that features a number of Python variations by manually putting in them and configuring your surroundings accordingly.

    Listed here are a couple of approaches to realize this:

    Some base pictures, like jessestuart/multi-python, are particularly designed to incorporate a number of Python variations. You should utilize such a picture as your base after which configure your Dockerfile to make use of the specified Python model.

    1FROM jessestuart/multi-python
    2
    3# Set the default Python model (e.g., Python 3.8)
    4RUN update-alternatives --set python /usr/bin/python3.8
    5
    6# Set up dependencies
    7RUN pip set up --upgrade pip
    8RUN pip set up some-package

    You possibly can manually set up a number of Python variations in a single Docker picture. This strategy requires extra setup and configuration.

    1FROM ubuntu:20.04
    2
    3# Set up dependencies for constructing Python
    4RUN apt-get replace && apt-get set up -y
    5 software-properties-common
    6 build-essential
    7 wget
    8 curl
    9 libssl-dev
    10 zlib1g-dev
    11 libbz2-dev
    12 libreadline-dev
    13 libsqlite3-dev
    14 llvm
    15 libncurses5-dev
    16 libncursesw5-dev
    17 xz-utils
    18 tk-dev
    19 libffi-dev
    20 liblzma-dev
    21 python3-openssl
    22 git
    23
    24# Set up Python 3.8
    25RUN add-apt-repository ppa:deadsnakes/ppa &&
    26 apt-get replace &&
    27 apt-get set up -y python3.8 python3.8-dev python3.8-venv
    28
    29# Set up Python 3.9
    30RUN apt-get set up -y python3.9 python3.9-dev python3.9-venv
    31
    32# Set default Python model (e.g., Python 3.8)
    33RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
    34
    35# Set up pip for each variations
    36RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py &&
    37 python3.8 get-pip.py &&
    38 python3.9 get-pip.py
    39
    40# Clear up
    41RUN rm get-pip.py && apt-get clear
    42
    43# Instance: Set up a package deal with Python 3.8
    44RUN python3.8 -m pip set up some-package
    45
    46# Instance: Set up a package deal with Python 3.9
    47RUN python3.9 -m pip set up another-package

    You should utilize pyenv to handle a number of Python variations inside a Docker container. This strategy is extra versatile however requires further setup.

    1FROM ubuntu:20.04
    2
    3# Set up dependencies
    4RUN apt-get replace && apt-get set up -y
    5 curl
    6 git
    7 build-essential
    8 libssl-dev
    9 zlib1g-dev
    10 libbz2-dev
    11 libreadline-dev
    12 libsqlite3-dev
    13 wget
    14 llvm
    15 libncurses5-dev
    16 libncursesw5-dev
    17 xz-utils
    18 tk-dev
    19 libffi-dev
    20 liblzma-dev
    21 python3-openssl
    22
    23# Set up pyenv
    24RUN curl https://pyenv.run | bash
    25
    26# Set surroundings variables for pyenv
    27ENV PATH="/root/.pyenv/bin:/root/.pyenv/shims:${PATH}"
    28RUN echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
    29
    30# Set up Python variations
    31RUN pyenv set up 3.8.10
    32RUN pyenv set up 3.9.5
    33
    34# Set world Python model
    35RUN pyenv world 3.8.10
    36
    37# Set up packages
    38RUN pip set up some-package

    Whereas a Dockerfile itself doesn’t inherently help a number of Python variations, you possibly can configure a Docker picture to incorporate and handle a number of variations utilizing the strategies described above. Every strategy has its personal trade-offs by way of complexity and suppleness, so select the one that most closely fits your wants.



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleTSMC to Invest $100B in 3 New U.S. Fabs, Packaging, R&D
    Next Article Mastering 1:1s as a Data Scientist: From Status Updates to Career Growth
    Team_AIBS News
    • Website

    Related Posts

    Machine Learning

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 2025
    Machine Learning

    Blazing-Fast ML Model Serving with FastAPI + Redis (Boost 10x Speed!) | by Sarayavalasaravikiran | AI Simplified in Plain English | Jul, 2025

    July 2, 2025
    Machine Learning

    From Training to Drift Monitoring: End-to-End Fraud Detection in Python | by Aakash Chavan Ravindranath, Ph.D | Jul, 2025

    July 1, 2025
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Revisiting Benchmarking of Tabular Reinforcement Learning Methods

    July 2, 2025

    I Tried Buying a Car Through Amazon: Here Are the Pros, Cons

    December 10, 2024

    Amazon and eBay to pay ‘fair share’ for e-waste recycling

    December 10, 2024

    Artificial Intelligence Concerns & Predictions For 2025

    December 10, 2024

    Barbara Corcoran: Entrepreneurs Must ‘Embrace Change’

    December 10, 2024
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    Most Popular

    Musk’s xAI buys his social media platform X

    March 29, 2025

    Here Are the Cities Where Your Paycheck Goes the Farthest

    January 26, 2025

    AWS Bedrock Knowledge Bases and RAG | by Javokhir Shoyusupov | Jan, 2025

    January 16, 2025
    Our Picks

    Revisiting Benchmarking of Tabular Reinforcement Learning Methods

    July 2, 2025

    Is Your AI Whispering Secrets? How Scientists Are Teaching Chatbots to Forget Dangerous Tricks | by Andreas Maier | Jul, 2025

    July 2, 2025

    Qantas data breach to impact 6 million airline customers

    July 2, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Business
    • Data Science
    • Machine Learning
    • Technology
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2024 Aibsnews.comAll Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.