Python Tutorial: VENV (Windows) - Summary
-
Introduction to Virtual Environments (00:00 - 00:27)
- Overview of the built-in
venvmodule in Python. - Comparison with
virtualenvandpipenv. - Focus on Windows usage in this tutorial.
- Overview of the built-in
-
Why Use Virtual Environments? (00:27 - 01:25)
- Avoid dependency conflicts between different projects.
- Example: Running Django 1 and Django 2 separately without conflicts.
- Ensures project-specific package management.
-
Creating a Virtual Environment (01:25 - 03:15)
- Requires Python 3.3 or higher.
- Command:
python -m venv <environment_name>. - Example: Creating
project_envon the desktop.
-
Activating and Using the Virtual Environment (03:15 - 05:04)
- Activation command:
Scripts\activate.bat(Windows). - Verification using
where python. - Installed packages can be checked with
pip list.
- Activation command:
-
Installing Packages and Managing Dependencies (05:04 - 07:04)
- Install packages using
pip install <package_name>. - Use
pip freeze > requirements.txtto export dependencies. - Allows recreating environments using
pip install -r requirements.txt.
- Install packages using
-
Deactivating and Deleting the Virtual Environment (07:04 - 08:08)
- Deactivation:
deactivate. - Deletion:
rmdir /s /q <environment_name>or manually remove the folder.
- Deactivation:
-
Best Practices (08:08 - 11:43)
- Place virtual environments inside project folders.
- Avoid committing virtual environments to version control (use
.gitignore). - Store dependencies in
requirements.txt.
-
Creating a Virtual Environment with System Packages (12:47 - 15:57)
- Use
--system-site-packagesto access global Python packages. - Installed packages within the environment do not affect system packages.
pip list --localshows only locally installed packages.
- Use
-
Final Thoughts and Recommendations (15:57 - End)
venvis simpler thanvirtualenvorpipenv, and suitable for most cases.- Encouragement to ask questions and support the channel.
This summary captures the key points of the tutorial while maintaining a structured flow. Let me know if you need any refinements! 😊
沒有留言:
張貼留言