Creating Your Own Python Sandbox
Table of contents
In the dynamic world of software development, maintaining a clean and organized codebase is paramount to project success. As projects evolve and dependencies accumulate, the risk of conflicts and compatibility issues increases. This is where virtual environments (venvs) step in as saviors, providing isolated sandboxes for each project and ensuring harmony among your project's dependencies.
Virtual environments, as the name suggests, create self-contained Python environments within a project directory. They encapsulate all the project's dependencies, preventing them from interfering with other projects or the global Python installation. This isolation is crucial for maintaining stability and reproducibility, especially when dealing with multiple projects simultaneously
To create a virtual environment in a project folder in Windows:
Open a command-prompt terminal
Navigate to the folder where you want to create your project and virtual environment. example: cd my_project
Create the virtual environment using the venv module. You can name the virtual environment anything you want, but a common name is env. For example:
py -m venv env
This will create a folder called env inside the project folder, which will contain the Python interpreter and the site-packages directory where you can install your dependencies.
Activate the virtual environment by running the activate script inside the env/Scripts folder. For example: env\Scripts\activate
You should see the name of the virtual environment in parentheses before the prompt, indicating that the virtual environment is active. For example: (env) C:\Users\Paul\ninja_project>
You can now install any packages you need for your project using pip. For example, if you want to install Django, you can use the following command: pip install Django
To deactivate the virtual environment, you can use the deactivate command. For example: deactivate
The prompt will return to normal, indicating that the virtual environment is no longer active.
Subscribe to my newsletter
Read articles from Meeran E. Mandhini directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Meeran E. Mandhini
Meeran E. Mandhini
Hello, I'm Meeran E. Mandhini from Chennai, India, with a deep interest in technology, especially personal computers. My love for tech has inspired my children, especially my son Ashik Nesin, who dreams of starting his own software company. He started working towards this dream at just 13 years old. Now, I'm excited to dive back into my own interest in software development. The progress in artificial intelligence has made it easier for people like me to learn programming and software development. With my son's knowledge and the power of AI, I'm ready to delve into the software development world. Through this blog, I'll share my journey, experiences, and insights. I hope to connect with other budding developers and contribute to the software development community.