Skill - Using virtual environments in python projects
Skills Required
- Setup python development environment
- Install and manage python packages
- Virtual environments using ‘venv’
Please make sure to have all the skills mentioned above to understand and execute the code mentioned below. Go through the above skills if necessary for reference or revision
Demo Project with virtual environment
A sample python demo project with virtual environment is hosted at https://github.com/nagasudhirpulla/sample_python_script_template
You can download the project files here
Scenario - Create a virtual environment from existing requirements.txt
Run / Double click the following batch files in the below sequence
- create_env.bat
- install_env.bat
Scenario - Update the current virtual environment packages in requirements.txt
Run / Double click the following batch file
- freeze_env.bat
Scenario - Run the python project with the created virtual environment
Run / Double click the following batch file
- run.bat
Each batch file explained
- create_env.bat - creates a new virtual environment
- install_env.bat - installs packages from
requirements.txt
in the virtual environment - activate_env.bat - activates the created virtual environment
- freeze_env.bat - writes all the virtual environment packages into
requirements.txt
file
Further Reading
Video
You can the video on this post here
Comments
Post a Comment