Title: Python Virtual Environments: A Primer – Real Python
Open Graph Title: Python Virtual Environments: A Primer – Real Python
Description: Create isolated project setups on all platforms, and gain a deep understanding of Python's virtual environments created with the venv module.
Open Graph Description: Create isolated project setups on all platforms, and gain a deep understanding of Python's virtual environments created with the venv module.
Mail addresses
?subject=Python article for you&body=Python Virtual Environments: A Primer on Real Python
https://realpython.com/python-virtual-environments-a-primer/
Opengraph URL: https://realpython.com/python-virtual-environments-a-primer/
X: @realpython
Domain: realpython.com
{
"@context": "http://schema.org",
"@type": "Article",
"headline": "Python Virtual Environments: A Primer",
"image": {
"@type": "ImageObject",
"url": "https://files.realpython.com/media/Python-Virtual-Environments_Watermarked.4c787192d42f.jpg",
"width": 1920,
"height": 1080
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://realpython.com/python-virtual-environments-a-primer/",
"lastReviewed": "2024-11-30",
"author": {
"@type": "Person",
"name": "Martin Breuss",
"image": "https://realpython.com/cdn-cgi/image/width=456,height=456,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/martin_breuss_python_square.efb2b07faf9f.jpg",
"url": "https://realpython.com/team/mbreuss/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
"reviewedBy": [
{
"@type": "Person",
"name": "Aldren Santos",
"image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
"url": "https://realpython.com/team/asantos/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Brenda Weleschuk",
"image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
"url": "https://realpython.com/team/bweleschuk/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Bartosz Zaczy\u0144ski",
"image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
"url": "https://realpython.com/team/bzaczynski/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Dan Bader",
"image": "https://realpython.com/cdn-cgi/image/width=1000,height=1000,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/daniel-square.d58bf4388750.jpg",
"url": "https://realpython.com/team/dbader/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Geir Arne Hjelle",
"image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/gahjelle.470149ee709e.jpg",
"url": "https://realpython.com/team/gahjelle/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Joanna Jablonski",
"image": "https://realpython.com/cdn-cgi/image/width=800,height=800,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/jjablonksi-avatar.e37c4f83308e.jpg",
"url": "https://realpython.com/team/jjablonski/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Kate Finegan",
"image": "https://realpython.com/cdn-cgi/image/width=400,height=400,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/VZxEtUor_400x400.7169c68e3950.jpg",
"url": "https://realpython.com/team/kfinegan/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Michael Herman",
"image": "https://realpython.com/cdn-cgi/image/width=160,height=160,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/mike.fa94729a1e81.jpg",
"url": "https://realpython.com/team/mherman/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
}
]
},
"datePublished": "2024-11-30T14:00:00+00:00",
"dateModified": "2024-11-30T14:09:26.165143+00:00",
"publisher": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": {
"@type": "ImageObject",
"url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
"width": 512,
"height": 512
},
"description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
"slogan": "Become a Python Expert",
"email": "info@realpython.com",
"sameAs": [
"https://github.com/realpython",
"https://www.youtube.com/realpython",
"https://twitter.com/realpython",
"https://x.com/realpython",
"https://www.linkedin.com/company/realpython-com/",
"https://www.facebook.com/learnrealpython",
"https://www.instagram.com/realpython",
"https://www.tiktok.com/@realpython.com"
]
},
"author": {
"@type": "Person",
"name": "Martin Breuss",
"image": "https://realpython.com/cdn-cgi/image/width=456,height=456,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/martin_breuss_python_square.efb2b07faf9f.jpg",
"url": "https://realpython.com/team/mbreuss/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
"description": "Create isolated project setups on all platforms, and gain a deep understanding of Python's virtual environments created with the venv module.",
"hasPart": {
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "How do you create a Python virtual environment?",
"acceptedAnswer": {
"@type": "Answer",
"text": "You create a Python virtual environment by using the venv module. Open your terminal or command prompt and run the command python -m venv venv/, replacing venv/ with the folder name you want to give your virtual environment. This command sets up a new directory with a copy or symlink of the Python interpreter and a few supporting files.
"
}
},
{
"@type": "Question",
"name": "Why should you use virtual environments in Python?",
"acceptedAnswer": {
"@type": "Answer",
"text": "You should use virtual environments in Python to manage dependencies for different projects separately. This prevents conflicts between package versions and keeps your global Python environment clean. Virtual environments ensure that each project can have its own set of dependencies, independent of one another and the system-wide Python packages.
"
}
},
{
"@type": "Question",
"name": "How do you activate a virtual environment on Windows?",
"acceptedAnswer": {
"@type": "Answer",
"text": "To activate a virtual environment on Windows, navigate to your environment’s directory in the command prompt and run the command venv\\Scripts\\activate. Once activated, the environment name will appear in your command prompt, indicating that the virtual environment is active.
"
}
},
{
"@type": "Question",
"name": "Can you use different versions of Python in virtual environments?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Yes, you can use different versions of Python in virtual environments. When creating a virtual environment, you can specify the Python interpreter you want to use by providing the path to the desired Python executable. This allows you to maintain environments with different Python versions as needed for your projects.
"
}
},
{
"@type": "Question",
"name": "How do you install packages in a Python virtual environment?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Once you activate your virtual environment, you can install packages using pip. Run the command python -m pip install <package-name> to install a package in the active environment. This ensures that the installed package is isolated within the virtual environment, preventing conflicts with other projects.
"
}
}
]
}
}
| author | Real Python |
| twitter:card | summary_large_image |
| twitter:image | https://files.realpython.com/media/Python-Virtual-Environments_Watermarked.4c787192d42f.jpg |
| og:image | https://files.realpython.com/media/Python-Virtual-Environments_Watermarked.4c787192d42f.jpg |
| twitter:creator | @realpython |
| og:type | article |
Links:
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover
Robots: max-image-preview:large