ThoughtWorks
  • Contacto
  • Português
  • Deutsch
  • English
  • 中文
Visión general
  • Cultura de ingeniería, mentalidad de entrega

    Adopta un enfoque moderno para el desarrollo de software y entrega valor más rápido.

    Toma de desiciones Inteligentes

    Aprovecha los resultados de tus datos para descubrir nuevas fuentes de valor

  • Modelo Operativo sin Frincción

    Mejora la habilidad de tu empresa para adaptarse al cambio

    Estrategia de Plataforma

    Crea plataformas tecnológicas que de adapten a su estrategia de negocio

  • Experience Design y Product Capabilities

    Diseña, entrega y evoluciona rápidamente productos y experiencias excepcionales

    Asociaciones

    Aprovechar nuestra red de socios confiables para ampliar los resultados que brindamos a nuestros clientes

Visión general
  • Sector Automotriz
  • Cleantech y Servicios Públicos
  • Servicios Financieros y Aseguradoras
  • Servicios Médicos
  • Medios y Publicidad
  • Organizaciones sin fines de lucro
  • Sector Público
  • E-commerce y Retail
  • Viajes y Transporte
Visión general

Destacados

  • Tecnología

    Una exploración profunda de tecnología empresarial y excelencia en ingeniería

  • Negocios

    Mantenerse actualizado con los últimos insights empresariales y de industria para líderes digitales

  • Cultura

    El espacio para encontrar contenido y tips de desarrollo profesional, y nuestra visión sobre la justicia social y la inclusión

Publicaciones Digitales y Herramientas

  • Radar Tecnológico

    Nuestra guía de tendencias tecnológicas actuales

  • Opiniones

    Una publicación para líderes digitales

  • Digital Fluency Model

    Un modelo para priorizar las capacidad digitales necesarias para navegar en la incertidumbre

  • Decoder

    Una guía tecnológica de la A a la Z para líderes de negocio

Todos los Insights

  • Artículos

    Opiniones profesionales que ayudarán al crecimiento de tu negocio

  • Blogs

    Opiniones personales de ThoughtWorkers de todo del mundo

  • Libros

    Navega a través de nuestra extensa biblioteca

  • Podcasts

    Emocionantes charlas sobre las últimas tendencias en negocios y tecnología

Visión general
  • Proceso de Aplicación

    Descubre lo que te espera durante nuestro proceso de selección

  • Graduados y cambio de carreras

    Empieza tu carrera en tecnología con el pie derecho

  • Ofertas de trabajo

    Encuentra puestos vacantes en tu región

  • Mantente conectado

    Suscríbete a nuestro boletín mensual

Visión general
  • Conferencias y eventos
  • Diversidad e Inclusión
  • Noticias
  • Código abierto
  • Nuestros líderes
  • Cambio Social
  • Português
  • Deutsch
  • English
  • 中文
ThoughtWorksMenú
  • Cerrar   ✕
  • Nuestros Servicios
  • ¿Con quién trabajamos?
  • Insights
  • Carreras
  • Acerca de Nosotros
  • Contacto
  • Regresar
  • Cerrar   ✕
  • Visión general
  • Cultura de ingeniería, mentalidad de entrega

    Adopta un enfoque moderno para el desarrollo de software y entrega valor más rápido.

  • Experience Design y Product Capabilities

    Diseña, entrega y evoluciona rápidamente productos y experiencias excepcionales

  • Modelo Operativo sin Frincción

    Mejora la habilidad de tu empresa para adaptarse al cambio

  • Toma de desiciones Inteligentes

    Aprovecha los resultados de tus datos para descubrir nuevas fuentes de valor

  • Asociaciones

    Aprovechar nuestra red de socios confiables para ampliar los resultados que brindamos a nuestros clientes

  • Estrategia de Plataforma

    Crea plataformas tecnológicas que de adapten a su estrategia de negocio

  • Regresar
  • Cerrar   ✕
  • Visión general
  • Sector Automotriz
  • Cleantech y Servicios Públicos
  • Servicios Financieros y Aseguradoras
  • Servicios Médicos
  • Medios y Publicidad
  • Organizaciones sin fines de lucro
  • Sector Público
  • E-commerce y Retail
  • Viajes y Transporte
  • Regresar
  • Cerrar   ✕
  • Visión general
  • Destacados

  • Tecnología

    Una exploración profunda de tecnología empresarial y excelencia en ingeniería

  • Negocios

    Mantenerse actualizado con los últimos insights empresariales y de industria para líderes digitales

  • Cultura

    El espacio para encontrar contenido y tips de desarrollo profesional, y nuestra visión sobre la justicia social y la inclusión

  • Publicaciones Digitales y Herramientas

  • Radar Tecnológico

    Nuestra guía de tendencias tecnológicas actuales

  • Opiniones

    Una publicación para líderes digitales

  • Digital Fluency Model

    Un modelo para priorizar las capacidad digitales necesarias para navegar en la incertidumbre

  • Decoder

    Una guía tecnológica de la A a la Z para líderes de negocio

  • Todos los Insights

  • Artículos

    Opiniones profesionales que ayudarán al crecimiento de tu negocio

  • Blogs

    Opiniones personales de ThoughtWorkers de todo del mundo

  • Libros

    Navega a través de nuestra extensa biblioteca

  • Podcasts

    Emocionantes charlas sobre las últimas tendencias en negocios y tecnología

  • Regresar
  • Cerrar   ✕
  • Visión general
  • Proceso de Aplicación

    Descubre lo que te espera durante nuestro proceso de selección

  • Graduados y cambio de carreras

    Empieza tu carrera en tecnología con el pie derecho

  • Ofertas de trabajo

    Encuentra puestos vacantes en tu región

  • Mantente conectado

    Suscríbete a nuestro boletín mensual

  • Regresar
  • Cerrar   ✕
  • Visión general
  • Conferencias y eventos
  • Diversidad e Inclusión
  • Noticias
  • Código abierto
  • Nuestros líderes
  • Cambio Social
Blogs
Selecciona un tema
Ver todos los temasCerrar
Tecnología 
Gestión de Proyectos Agiles La Nube Entrega Continua Ciencia e Ingenieria de Datos Defendiendo el Internet Libre Arquitectura Evolutiva Experiencia de Usuario IoT  Lenguajes, Herramientas y Frameworks Modernización de sistemas heredados Machine Learning & Artificial Intelligence Microservicios Plataformas Seguridad Pruebas de Software Estrategia Digital 
Negocio 
Servicios Financieros Salud Global Innovación Ventas  Transformación 
Carreras 
Hacks Para Tu Carrera Diversidad e Inclusión Cambio Social 
Blogs

Temas

Elegir tema
  • Tecnología
    Tecnología
  • Tecnología Visión General
  • Gestión de Proyectos Agiles
  • La Nube
  • Entrega Continua
  • Ciencia e Ingenieria de Datos
  • Defendiendo el Internet Libre
  • Arquitectura Evolutiva
  • Experiencia de Usuario
  • IoT
  • Lenguajes, Herramientas y Frameworks
  • Modernización de sistemas heredados
  • Machine Learning & Artificial Intelligence
  • Microservicios
  • Plataformas
  • Seguridad
  • Pruebas de Software
  • Estrategia Digital
  • Negocio
    Negocio
  • Negocio Visión General
  • Servicios Financieros
  • Salud Global
  • Innovación
  • Ventas
  • Transformación
  • Carreras
    Carreras
  • Carreras Visión General
  • Hacks Para Tu Carrera
  • Diversidad e Inclusión
  • Cambio Social
Lenguajes, Herramientas y FrameworksBangaloreTecnología

Python Working Environment for Beginners: Part 2

Surya Sreedevi Vedula Surya Sreedevi Vedula

Published: Oct 24, 2014

Part 2 of Python Working Environment. For ways to set Python Working Environment, check out Part 1 here.

Creating Virtual Environments

Understanding Virtual Environments

As we saw in the Installing Packages section , when we install third-party dependencies using pip (or easy_install), they are installed in the <python-base-dir>/lib/python<major>.<minor>/site-packages directory. But, what if two different applications (hosted on the same machine) need two different versions of the same package? Virtual Environments solve this problem by isolating one application's environment from another. These environments are based on a Python installation and can be considered as light-weight containers for holding application-specific dependencies. Virtual environments also come in handy when we do not have write permissions to the Python installation's site-packages directory.

Python virtual environments were originally provided by “virtualenv” package. Starting from Python 3.3, virtual environments have been added to Python language in the module “venv”. In this post, we will see how to create virtual environments using “virtualenv” as well as Python’s out-of-the-box virtual environments provided using “venv”.

Virtual Environments using "virtualenv"

“virtualenv” creates an isolated Python environment in a directory structure which contains the “site-packages” directory. When we activate the virtual environment and install packages, the packages are placed in the virtual environment's “site-packages” directory instead of Python Installation's site-packages directory.

Let us install virtualenv and try to create a virtual environment using it.

# Update PATH to include Python Installation's bin directory
$ export PATH= <python-base-dir>/bin:$PATH
# Install virtualenv using pip.
$ pip install virtualenv

After the installation of “virtualenv”, we can create a new virtual environment in an empty / non-existent directory using “virtualenv”.

$ virtualenv my-project-env

The command virtualenv does the below important things:

  • Creates “python”, “easy_install” and “pip” executables for the virtual environment in “bin” directory
  • Creates a “lib” directory to hold all the libraries and a lib/python<major>.<minor>/site-packages directory to hold the third-party dependencies.
  • Creates an activate script in the “bin” directory which is used to bring the virtual environment into effect.

Let us now proceed to activate the environment and install a package.

# Activate the Python Environment. This also changes the shell prompt to indicate the environment.
$ cd my-project-env
$ source bin/activate

Observe that the shell prompt is changed to (my-project-env) indicating that the virtual environment is activated.

Let us now try to install “requests” package in the virtual environment and notice that it is installed in the “site-packages” of the virtual environment and isolated from the Python installation. 

# Install “requests” package in the virtual environment.
(my-project-env) $ pip install requests
# Verify that “requests” is installed in virtual environment using “pip show” command.
(my-project-env) $ pip show requests

Once you are done working with the virtual environment, you can deactivate the virtual environment using the function call 'deactivate'.

(my-project-env) $ deactivate

Virtual Environments using "venv"

Virtual environments have been added to Python language from Python 3.3 in the module “venv”. The “pyvenv” executable helps you create the virtual environments. The detailed documentation can be found here. One important difference in Python 3.3 virtual environments from those created by “virtualenv” package is that the binaries “pip” and “easy_install” are not copied over to “bin” directory, because of which, we should install these packages additionally in the virtual environment. However, with Python 3.4.1, this issue has been fixed and "pip" executable is made available in the bin directory of the virtual environment for our ready use.

Let us try to create a virtual environment using "pyvenv" executable, install "requests" package and verify that the packages are installed in the virtual environment.

# Create a virtual environment in the directory my-project-env.
$ pyvenv my-project-venv
# Change to the virtual environment directory.
$ cd my-project-venv
# Activate the virtual environment.
$ source bin/activate
# Install “requests” package.
(my-project-venv) $ pip install requests
# Observe that “requests” is installed in the virtual environment using “pip show” command.
(my-project-venv) $ pip show requests

Once you are done working with the virtual environment, you can deactivate the virtual environment using the function call 'deactivate'.

(my-project-env) $ deactivate

Summary

In a nutshell, setting up basic Python environments involves installing the required version of Python, creating virtual environments for your project based on the Python installation and installing the required third-party dependencies using “pip”.

I hope this post helps you understand how to set up basic Python environments and gives an overview of the ecosystem around packages and their management using virtual environments.

References

  • Installing Python from Sources
  • Setuptools documentation
  • pip documentation
  • Why use pip over easy_install - Stack Overflow

Ready to shape the future of tech?

Join our team of passionate and bright technologists.

Join us
  • Nuestros Servicios
  • ¿Con quién trabajamos?
  • Insights
  • Carreras
  • Acerca de Nosotros
  • Contacto

WeChat

×
QR code to ThoughtWorks China WeChat subscription account

Relaciones con medios de comunicación y analistas | Política de Privacidad | Modern Slavery statement ThoughtWorks| Accesibilidad | © 2021 ThoughtWorks, Inc.