Clean New Projects with venv - Virtual Environments
Skills:
Tool Use & Function Calling80%
Key Takeaways
The video demonstrates how to create and manage virtual environments for Python projects using the venv module, allowing for isolated package installations and version management. It covers creating virtual environments, activating and deactivating them, installing packages, and exporting package lists to requirements.txt files.
Full Transcript
what is going on guys welcome back in this video today we're going to learn how to professionally set up virtual environments for new projects in Python so let us get right into it [Music] alright so oftentimes we're going to be working on multiple different python projects at the same time and those different python projects rely on different packages and oftentimes on different versions of the same packages so for example I might have a data science project that is a little bit older and it relies on Panda's version 1. so pandas one point something and I might have a newer version or a newer project which relies on pandas version 2. something and those are incompatible and on my system I can only have one pandas installation so when I open up the terminal for example and I type pip3 list or to have it in the requirements txt format pip3 freeze you can see that each package has exactly one version number I cannot have pandas one point something and pandas two point something installed because when I install one of them the other one is going to be uninstalled so for example if I say now pip3 install I think I have pandas1 installed here because of a project that I'm working on without an environment and if I say now I want to install pandas equals equals version 2. something uh then it's going to uninstall the installation that I already have as you can see here uninstalling pandas 1.5 to install pandas 2. uh 2.0.3 and the same thing the other way around if I install pandas1 it's going to uninstall pandas2 and because I need both versions depending on the project the best practice way to do that the professional way to work with multiple projects is to create so-called virtual environments so for this I'm going to go to my desktop let's say here now I have two projects let's say project one and I have project two and instead of just using my python installation and all the packages that I have on my system I'm going to create now virtual environments for those two different projects and how do I do that there is a core python tool called vnf that we can use to create these virtual environments now I also have a video already on this channel on Virtual enf which is a third party tool so a package that is not a core python package and this is useful if you're working with older python versions but since python 3.3 there is this uh core python module vnf available and this is the go-to way to work with virtual environments so let's say this is now the project one here we can open up the terminal and we can create a new virtual environment and the idea of a virtual environment is that you have specific package versions and only those packages are installed in that particular environment so you don't get all the packages you have on your system you only get the packages that you install for that virtual environment and you only get the package versions that you specify here inside of that virtual environment and this is useful for multiple reasons first of all of course because you can have different versions of pandas for example for the different projects but second of all you can also just export everything that is installed in the environment into and into a requirement txt file so that people can easily install everything that you have in your virtual environment to reproduce uh the setup basically so there is no real convention for naming the environment you can call your environment whatever you like however the I wouldn't say convention but the go-to way to do that is to create an environment inside of a project folder and to call it either vnf Dot N or Dot vnf and I think that the dot VN version is actually recommended in the python documentation so we're going to go with this one so to create a virtual environment with vnf we're going to say python or Python 3 depending on your terminal and operating system and then we're going to say Dash M vnf and then the name of the environment in our case Dot vnf and as you can see now here it creates a DOT vnf directory in my project folder and what I have to do now is I have to navigate into that directory here and then I'm going to just say here on Linux Source bin and then uh Source bin and then activate and this is going to activate the virtual environment now if I say pip 3 list you will see that I have exactly two packages installed here pip and setup tools so basically nothing and if I say now pip3 install pandas it's going to install the most recent version of pandas and you will see here in a second this is pandas2 so pane is 2.0.3 and if I now say deactivate in this environment uh and if I now say pip3 list and I grab the pandas line you will see that on my main installation without a virtual environment I have pandas one but if I do the same thing here again with activate and then the same command you can see I have pandas 2.0.3 installed so I have different pandas versions depending on the environment and of course I can do the same thing now I can deactivate again and I can go back to the desktop I can go to project uh project two and here I can create another environment with the same name so Python 3 vnfindin Dot vnf and in here for example I do the same thing Source dot vnf bin activate and then I can just say pip 3 install pandas equals equals one point whatever and then it installs a different pandas version in this virtual environment so depending on which virtual environment I'm in I'm going to be working with different packages and of course here I can also now install something else like for example uh opencv Dash python and the good thing about such a virtual environment is now that I can go ahead and Export everything I can take all the installed modules with the versions that are installed and I can export them to a requirements txt file so pip3 freeze is what I want to get this is the text and I can just take this and feed it into a requirements txt file and then I can open this file and you can see it is what we have installed here in this virtual environment so when I create some project here and I want to pass this to someone to tell them look this is what I have and if you want to run this on your systems on your system those are the packages that you need to have installed they can just run pip3 install Dash R requirements txt and they will if they have their own virtual environment they can then reproduce the exact setup that I have here at least on a python level so of course system packages are not included here but this is also a benefit of virtual environments now another way to see that you're in a virtual environment is to see where python is so you can say which Python 3 and you can see that the Python 3 that we're currently accessing here is part of the virtual environment this is not the case if I deactivate in this case you will see that it's in user bin python 3. so yeah this is how you work with virtual environments using the core python module vnf so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you next video and bye
Original Description
In this video we learn how to properly create new Python projects with virtual environments and venv.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: https://www.neuralnine.com/books/
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
👕 Programming Merch: https://www.neuralnine.com/shop
💼 Services 💼
💻 Freelancing & Tutoring: https://www.neuralnine.com/services
🌐 Social Media & Contact 🌐
📱 Website: https://www.neuralnine.com/
📷 Instagram: https://www.instagram.com/neuralnine
🐦 Twitter: https://twitter.com/neuralnine
🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/
📁 GitHub: https://github.com/NeuralNine
🎙 Discord: https://discord.gg/JU4xr8U3dm
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
I Grepped My Own Claude Code Logs and Found the Hidden Tag Anthropic Never Shows You
Dev.to · Sho Naka
Dockered Claude: keeping research code compilable but obscured from my AI agent
Dev.to AI
Import AI 466: The bitter lesson for robotics, AIs complete week-long programming tasks; and OpenAI's accidental AI hacker
Import AI
The Junior Developer Pipeline Is Broken... And AI Broke It
Dev.to · Nazar Boyko
🎓
Tutor Explanation
DeepCamp AI