Arregla Pyenv que estropea Distrobox

Aprende a evitar que pyenv filtre el Python del host al contenedor con Distrobox: desactiva la función pyenv y limpia PATH usando un .bashrc inteligente.

28 sept 2025 • 3 min read • Q2BSTUDIO Team

Inteligencia-Artificial-

Has configurado tu entorno de desarrollo ideal: tu sistema host, quizá Pop!_OS o Ubuntu, usa pyenv para gestionar varias versiones de Python y para compilaciones limpias y reproducibles trabajas dentro de un contenedor Fedora creado con Distrobox. Todo parece perfecto hasta que algo falla. Dentro del contenedor ejecutas which python3 y obtienes la ruta a ~/.pyenv/shims/python3 de tu host en lugar del python de Fedora. El contenedor ya no está limpio: el host se ha filtrado dentro.

No entres en pánico. Es un problema común y la solución es sencilla cuando entiendes lo que ocurre.

El culpable oculto es una función de shell de pyenv. Puede parecer que solo es cosa del PATH, pero cuando en el host ejecutas eval $(pyenv init -) no solo se modifica el PATH sino que también se crea una función llamada pyenv que puede sobrescribir el comportamiento de python. Esa función se hereda al contenedor y tiene prioridad sobre cualquier ajuste de PATH que intentes hacer desde dentro.

La solución es clara: eliminar la función de shell y limpiar el PATH dentro del contenedor. La mejor práctica es hacer el .bashrc inteligente para detectar si estás en el host o dentro de un contenedor y aplicar las acciones adecuadas automáticamente.

A continuación tienes un bloque de ejemplo para sustituir tu configuración actual de pyenv en .bashrc. Está diseñado para funcionar en el host y para dejar los contenedores completamente limpios:

if [ -z ${CONTAINER_ID+x} ] ; then

# --- SISTEMA HOST ---

export PYENV_ROOT=$HOME/.pyenv

export PATH=$PYENV_ROOT/bin:$PATH

eval $(pyenv init -)

else

# --- INVITADO (contenedor Distrobox) ---

# 1. Desactivar la funcion pyenv heredada

pyenv() { :; }

# 2. Reconstruir PATH sin entradas de pyenv

_CLEAN_PATH=

OLD_IFS=$IFS ; IFS=: ; for p in $PATH ; do case $p in */.pyenv* ) ;; *) if [ -n $p ] ; then _CLEAN_PATH=${_CLEAN_PATH:+$_CLEAN_PATH:}$p ; fi ;; esac ; done

# Preponer las rutas nativas del contenedor para garantizar prioridad

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${_CLEAN_PATH}

IFS=$OLD_IFS ; unset _CLEAN_PATH OLD_IFS

fi

Guarda los cambios y cierra y vuelve a abrir tus terminales. En el host pyenv seguirá funcionando con normalidad. En tu contenedor Fedora obtendrás un python nativo en /usr/bin/python3 y no habrá fugas desde el host.

Por que esta es la solución adecuada: es una correccion limpia y mantenible. Pros: configuracion de una sola vez, aislamiento real tanto del PATH como de la funcion de shell, compatibilidad futura si decides instalar pyenv dentro del contenedor, y límites claros entre host y guest. Contras: funciona para bash; si usas zsh o fish deberas adaptar el enfoque, y depende de que .bashrc se cargue correctamente.

En Q2BSTUDIO como empresa de desarrollo de software y aplicaciones a medida ayudamos a equipos y organizaciones a mantener entornos de desarrollo confiables y seguros. Si necesitas construir soluciones profesionales a medida visita nuestra pagina de desarrollo de aplicaciones a medida y software a medida. Si además trabajas con infraestructuras cloud podemos ayudarte a integrar buenas practicas en AWS y Azure y optimizar despliegues, conoce nuestros servicios cloud AWS y Azure.

Ofrecemos servicios completos que incluyen inteligencia artificial para empresas, agentes IA, ciberseguridad y pentesting, servicios de inteligencia de negocio y Power BI, y automatizacion de procesos para que tu software a medida funcione de forma segura y escalable. Nuestro equipo de especialistas en inteligencia artificial y ciberseguridad asegura que tus entornos no solo sean productivos sino tambien resilientes.

Conclusión: con este ajuste en .bashrc recuperas el aislamiento entre host y contenedor, conservas la potencia de pyenv en tu equipo principal y evitas que pyenv se cuele donde no corresponde. Si necesitas asistencia profesional para aplicar estas configuraciones en proyectos reales o para diseñar soluciones a medida, contacta con Q2BSTUDIO y te ayudaremos a implementar la mejor estrategia técnica.

A BREAK?

Play for a moment before you go

OUR SERVICES

How we can help you

Artificial intelligence

AI agents, chatbots, and intelligent assistants that automate tasks and serve your customers 24/7 to improve the efficiency of your business.

More info

Software Development

Web, mobile, and desktop applications, intranets, e-commerce, SaaS, and management platforms designed for your company's specific needs.

More info

Cloud services

Migration, infrastructure, managed hosting, high availability, and security on Microsoft Azure and Amazon Web Services to help your business scale without limits.

More info

Cybersecurity and pentesting

Security audits, penetration testing and protection of applications, data and infrastructure on-premise and cloud, with ethical hacking and regulatory compliance.

More info

Business Intelligence

Dashboards and data analysis with Power BI: we integrate your sources, design dashboards and KPIs and turn your data into decisions.

More info

Process automation

We automate repetitive tasks and connect your applications with n8n, Power Automate, Make, and RPA, eliminating manual work and increasing productivity.

More info

Training for Companies

We train your teams in technology with criteria: web development, databases, Git, best practices and security, automation with n8n, artificial intelligence for companies and creation of AI solutions with Azure AI Foundry.

More info

Code Auditing

We audit the code that you, your team or an AI create: we tell you what is good and what to improve, we secure it and make it ready for production, web or app.

More info

AI Image Generation

We create for you the images that your business needs with artificial intelligence: product, networks, advertising, illustration and avatars. You tell us what you want and we deliver it ready to use.

More info

AI Video Generation

We create videos with artificial intelligence for you: promotional, networking, virtual presenters, dubbing and animations. You tell us the idea and we will deliver it assembled and ready to publish.

More info

AI Conversational Avatars

We create conversational avatars with AI – digital humans with a face and voice – that serve your customers and teams with the knowledge of your company, on your website, interactive monitors, WhatsApp or Teams.

More info

Online Marketing and AI

Google Ads, Meta Ads, LinkedIn Ads and AI Engine Positioning (GEO/AEO): we attract customers and make your brand appear where they search for you, also on ChatGPT, Gemini and Perplexity.

More info

Do you have a project in mind?

Tell us your vision and we'll turn it into a software solution. Whatever the scope, we make your idea real.

Live Chat