-
-
Notifications
You must be signed in to change notification settings - Fork 363
How To Install Python Setup Virtual Environment VENV Set Default Python System Path and Install Git
Full tutorial link > https://www.youtube.com/watch?v=B5U7LJOvH6g
How to install Python, have multiple Python installations, set system wide default Python version. How to compose venv for any Python installation, change Python default path, and install SD web UI properly. Discord: https://bit.ly/SECoursesDiscord.
If I have been of assistance to you and you would like to show your support for my work, please consider becoming a patron on 🥰 https://www.patreon.com/SECourses
Technology & Science: News, Tips, Tutorials, Tricks, Best Applications, Guides, Reviews
https://www.youtube.com/playlist?list=PL_pbwdIyffsnkay6X91BWb9rrfLATUMr3
Playlist of #StableDiffusion Tutorials, Automatic1111 and Google Colab Guides, DreamBooth, Textual Inversion / Embedding, LoRA, AI Upscaling, Pix2Pix, Img2Img
https://www.youtube.com/playlist?list=PL_pbwdIyffsmclLl0O144nQRnezKlNdx3
00:00:00 Very comprehensive guide to #Python installation on Windows
00:01:11 What is CMD - Command Prompt
00:01:56 How to open a cmd window and use it
00:02:04 How to run cmd as administrator
00:02:17 What is Git and why do we need Git
00:02:35 How to download and install Git
00:03:30 Why do we need Git large and how to download and install Git large
00:03:50 Why do we need specific Python versions
00:04:03 How to download and install any Python version
00:04:32 How to verify if Python installed or not
00:04:55 How to customize Python installation
00:05:17 Python add path checkbox during installation
00:06:20 How to verify your Python installed version
00:06:35 How to change or set system environment variables path of Python
00:07:15 How to install another Python version - multiple Python installations
00:08:30 How to change default Python version when having multiple Python installations
00:09:30 How to use specific Python installation when having multiple Python
00:09:35 What is Python venv and why do we need it
00:10:40 How to start cmd inside certain directory
00:10:55 How to compose a Python #venv
00:11:19 How to activate Python venv
00:11:58 How to compose a venv from different Python version
00:13:39 Demo of installed package separation from other Python installations inside venv
00:14:17 Where to find installed packages in Python installation folder
00:14:50 How to write a bash script to automatically activate Python venv and start a cmd
00:15:24 How to view extensions of files in Windows
00:15:43 The script itself to activate venv and start cmd
00:17:11 How to install Stable Diffusion Automatic1111 web UI
00:17:30 How to use Git clone to download entire project from GitHub repo
A Comprehensive Guide to Python Installation, Git, and Virtual Environments on Windows
Introduction
Python is a versatile and powerful programming language that has gained significant popularity in recent years. In this article, we will provide a step-by-step guide to installing Python on Windows, using the Command Prompt, working with Git, and setting up virtual environments using Python venv.
Getting Started with the Command Prompt
The Command Prompt (CMD) is a Windows command-line interface used to execute commands, navigate directories, and manage files. To open a CMD window, search for 'cmd' in the Start menu and select the application.
Git: Version Control for Your Code
Git is a widely-used distributed version control system that helps manage changes in your code over time. It allows multiple developers to collaborate on the same project, tracking their changes and preventing conflicts.
Managing Large Files with Git Large File Storage (LFS)
Git LFS is an extension that allows you to manage large files more efficiently. It replaces large files with text pointers in your Git repository, which makes it easier to work with large files while keeping your repository small. Visit the Git LFS website (https://git-lfs.github.com/) to download and install the extension.
Python Installation on Windows
There may be instances when you need a specific Python version for a project. To download and install any Python version, visit the official Python website (https://www.python.org/downloads/) and select the desired version. During the installation process, make sure to check the "Add Python to PATH" checkbox to ensure that the Python executable is added to your system's environment variables.
Working with Python Virtual Environments
Python venv allows you to create isolated environments for different projects, each with its own Python interpreter, packages, and dependencies. To create a virtual environment, open the CMD window in your project directory and run 'python -m venv env_name'. To activate the virtual environment, execute ' env_name\Scripts\activate' on Windows.
Installing Packages in a Virtual Environment
Packages installed inside a virtual environment are isolated from other installations. This is useful for managing project-specific dependencies without affecting the global Python installation. To view installed packages in the Python installation folder, navigate to the 'Lib\site-packages' directory inside the virtual environment.
thumb source: freepik wangxina
-
00:00:00 Greetings everyone.
-
00:00:01 Python has become the main programming language for open source machine learning and AI algorithms.
-
00:00:07 Therefore, having basic knowledge about Python is fundamental for running open source applications.
-
00:00:12 So today, I am going to cover all of these topics.
-
00:00:16 What is cmd, command prompt and how to start and use it.
-
00:00:20 What is git, how to install Git and Git large and how to use Git to download projects hosted
-
00:00:26 on GitHub or Hugging Face.
-
00:00:28 How to install Python on your computer.
-
00:00:31 How to set the environment variables path of Python to set the default Python.
-
00:00:36 How to install another version of Python so that you can have multiple Python for each
-
00:00:41 application if necessary.
-
00:00:43 How to change the default Python via the environment variables path.
-
00:00:47 What is Python venv short for virtual environment.
-
00:00:50 How to make a Python venv from any installed Python version.
-
00:00:54 How to write a quick bash shortcut script to start cmd, activate a 13 installed venv.
-
00:01:00 How to install Stable Diffusion Automatic1111 web UI using the correct Python version while
-
00:01:07 having different Python installations.
-
00:01:09 So let's begin with what is cmd.
-
00:01:12 Cmd or command prompt is a command line interface.
-
00:01:15 It allows users to interact with the operating system by entering text-based commands, providing
-
00:01:21 a more direct and powerful method for controlling the system, executing programs, and managing
-
00:01:27 files and directories.
-
00:01:29 Think of cmd as a way to communicate with your computer by typing commands instead of
-
00:01:34 using graphical interfaces like clicking and dragging with a mouse.
-
00:01:39 It's a more advanced and technical approach to managing your computer and can be faster
-
00:01:44 and more efficient for certain tasks.
-
00:01:47 Usually we are using cmd interface for running machine learning applications by executing
-
00:01:53 Python commands.
-
00:01:54 Therefore it is important to understand that.
-
00:01:57 Click your start icon in the left bottom of your windows type cmd and you will see this
-
00:02:03 interface.
-
00:02:04 You can run it either as administrator or just run it and the cmd window will be opened
-
00:02:09 like this.
-
00:02:10 There are several commands, but usually we don't need to use them, we just can use our
-
00:02:15 graphical user interface.
-
00:02:17 So what is Git and why do we need it?
-
00:02:19 Git is a distributed version control system.
-
00:02:21 We are going to use Git to download repositories hosted on Hugging Face or GitHub or other
-
00:02:28 Git repositories because usually open source projects are hosted on such websites and you
-
00:02:34 need to clone them to be able to use them.
-
00:02:37 To download Git just type google Git and you will get this link.
-
00:02:42 Click it.
-
00:02:43 Download for windows.
-
00:02:44 You should choose 64 bit for Git windows because usually all of the windows installations are
-
00:02:49 now 64 bit.
-
00:02:51 Once the download has been completed.
-
00:02:53 Open your downloads folder.
-
00:02:54 Double click it.
-
00:02:55 Click yes next next.
-
00:02:58 You don't need to change anything, just type next.
-
00:03:00 By the way: before installing, let me show you how to verify whether Git is installed
-
00:03:05 or not.
-
00:03:06 To verify it I am starting a cmd like this.
-
00:03:09 Just typing Git and you see Git is not recognized as an internal or external command.
-
00:03:15 So let's continue the installation.
-
00:03:17 I am not changing anything I am installing it as it is.
-
00:03:21 The installation has been completed.
-
00:03:22 We don't need to launch it.
-
00:03:24 After installation: we need to start another cmd window so that it will be activated.
-
00:03:29 Let's type Git and now you see the Git is installed.
-
00:03:33 We also need to install Git large to download very large model files from Hugging Face.
-
00:03:38 So just type Git large, open this link, click download, open downloads folder, and double
-
00:03:44 click the downloaded file.
-
00:03:46 Click yes, accept next, and next, and finish.
-
00:03:50 Python is very version dependent.
-
00:03:52 So based on the target project that you are going to use, you need to install correct
-
00:03:58 Python version.
-
00:04:00 The applications that I use recently uses all Python 3.10 version.
-
00:04:05 Therefore, I am going to install Python 3.10.6.
-
00:04:10 This is also the suggested version by the Stable Diffusion Automatic1111 web UI.
-
00:04:14 Just go to the link.
-
00:04:17 So it is important to download it from the correct site.
-
00:04:21 This is the site of it.
-
00:04:22 I am going to download the windows installer 64 bit version.
-
00:04:26 It is also recommended version.
-
00:04:28 Once the download has been completed right click it.
-
00:04:31 Run as administrator.
-
00:04:33 By the way, let me show you that Python is currently not installed on my computer.
-
00:04:37 So I opened a cmd window typing Python and you see it is opening Microsoft store to install
-
00:04:44 it.
-
00:04:45 But I don't suggest you to install it from Microsoft store.
-
00:04:48 So let's continue click run.
-
00:04:50 It will ask you to verify running.
-
00:04:52 Yes!
-
00:04:53 Okay, this is really important.
-
00:04:54 You really should customize your installation because if you install it inside users folder
-
00:05:01 the default folder, you may likely to encounter problems.
-
00:05:05 I have seen many people were encountering problems.
-
00:05:09 Therefore, I will customize installation and one another very important thing is you need
-
00:05:15 to check this add Python 3.10 to path checkbox.
-
00:05:20 If you want this version to be your default version.
-
00:05:24 Then click customize installation.
-
00:05:26 You can check all of these next.
-
00:05:28 Okay, you can also check all of these check boxes.
-
00:05:31 And the another important thing is I suggest you to install it directly inside your C drive.
-
00:05:38 So I am going to make the path as Python 3.10 and the last version 6.
-
00:05:44 Like this: install.
-
00:05:45 It will install everything to your computer.
-
00:05:48 If you have previously installed Python 3.10 point any version, it won't allow you to install
-
00:05:56 Python 3.10.6.
-
00:05:58 I think it is conflicting with other Python 3.10.x.
-
00:06:03 However, you can install different versions such as 3.11 or 3.9.
-
00:06:10 I will show you that as well.
-
00:06:12 Okay, the installation has been completed.
-
00:06:14 I also suggest you to disable path length limit to not have any problems.
-
00:06:20 So just click it and it is done.
-
00:06:22 Now when I start a new cmd window command prompt and type Python I see that Python 3.10.6
-
00:06:30 version is installed on my computer.
-
00:06:33 It is able to recognize it.
-
00:06:35 Why?
-
00:06:36 Because when I type env, it will bring me edit system environment variables.
-
00:06:42 Click it!
-
00:06:43 It will open this window in here.
-
00:06:45 Click environment variables and now you will see variable path in user variables and system
-
00:06:51 variables.
-
00:06:52 When you go to the system variables path and click edit you will see that the Python installed
-
00:06:58 folder is inserted into our path variable of system variables like this.
-
00:07:04 With this, it is able to recognize my installed Python version.
-
00:07:09 Also, we are seeing the Git installed versions as well in our edit environment variable screen.
-
00:07:16 So click ok.
-
00:07:17 Ok.
-
00:07:18 So this time let's install the latest Python version.
-
00:07:22 By the way, installing latest Python version is not the correct thing because majority
-
00:07:28 of the open source machine learning applications, AI applications are developed with a certain
-
00:07:35 Python version and Python backwards compatibility is extremely poor.
-
00:07:40 So when you upgrade your Python version, you will likely to encounter a lot of problems.
-
00:07:46 Installing the necessary Python version is extremely important.
-
00:07:50 So let's download it and install it as same as previous installation.
-
00:07:54 Okay, right click.
-
00:07:55 Run as administrator.
-
00:07:57 Now this time if you also add Python exe to your path, it will also be added to your path.
-
00:08:03 However, now this will become your default installation.
-
00:08:07 Let's see, customize installation.
-
00:08:09 Next, install everything.
-
00:08:11 I will make the folder of this installation as 311 version 3.
-
00:08:18 Like this install, the setup was successful.
-
00:08:21 Now let's start another cmd type Python and you see my default Python is now 3.11.3.
-
00:08:29 How can I return back to previous Python as a default version?
-
00:08:35 So let's type env and we will see the edit system environment variables click it open
-
00:08:41 environment variables and when I click path.
-
00:08:44 Now I am seeing the newest installed Python in the top.
-
00:08:49 So the logic of environment variables is whatever is at the top will be used first.
-
00:08:55 So I am going to move up my previous Python into the top like this.
-
00:09:00 And okay.
-
00:09:01 Okay, okay.
-
00:09:03 Opening another cmd window typing Python and you see now 3.10.6 is my newest default version.
-
00:09:12 However, you need to start a new cmd window.
-
00:09:15 Otherwise, the previously started cmd won't see this change.
-
00:09:20 This is important.
-
00:09:21 Now in my C drive I have two Python installations and I want to install a software Depending
-
00:09:30 on Python 3.11.
-
00:09:31 How can I use Python 3.11 without changing my default Python version?
-
00:09:38 The way of doing it is using Python venv.
-
00:09:42 Python venv short for virtual environment is a tool in Python that allows you to make
-
00:09:48 isolated Python environments.
-
00:09:49 This is really important.
-
00:09:51 Isolated.
-
00:09:52 That means that other installations, other applications will not conflict and cause problems
-
00:09:57 with our venv installations.
-
00:10:00 It is used to manage dependencies of different projects separately and avoid conflicts between
-
00:10:06 different versions of packages and libraries.
-
00:10:09 In other words, it allows you to create a sandboxed environment where you can install
-
00:10:14 specific versions of Python packages and libraries without affecting the rest of your system.
-
00:10:21 This is useful when you are working on multiple projects that require different versions of
-
00:10:25 the same library or package, or when you want to test your code in a clean environment without
-
00:10:32 any interference from other installed packages.
-
00:10:34 To making a new venv folder, we are going to utilize this prompt.
-
00:10:39 And let's say, I want to make a new virtual environment folder inside my C drive.
-
00:10:45 To start cmd inside my c drive or in any folder.
-
00:10:49 Just type cmd into the folder path like this.
-
00:10:52 It will start cmd window inside that folder, then type Python -m venv and give the virtual
-
00:11:01 environment folder name like test1, and it will generate a virtual environment inside
-
00:11:08 that folder.
-
00:11:09 This will be completely isolated from other installations.
-
00:11:13 And now inside test1 folder I have got everything of the Python installation.
-
00:11:20 So to activate this installation, enter inside scripts folder.
-
00:11:26 Open a cmd inside here like this.
-
00:11:29 You see currently my cmd is inside test1 scripts folder, type activate and now you are seeing
-
00:11:36 test1 is written like this.
-
00:11:39 This means that this cmd is running inside this virtual environment Python installation,
-
00:11:44 not the default Python installation.
-
00:11:47 Let's type Python.
-
00:11:48 Okay, it is displaying 3.10.6 why?
-
00:11:52 Because when we generated our first Python like this, it used our default Python installation.
-
00:11:59 What about if I want to make a virtual environment with Python 3.11.
-
00:12:04 Then what I need to do is instead of typing Python, go to your Python 3.11 installation.
-
00:12:12 In here you will see Python application like this.
-
00:12:16 While pressing left shift on your keyboard, right click it will give you copy as path
-
00:12:22 option, copy as path and change this like this.
-
00:12:26 So now when making new virtual environment, it will use this Python version.
-
00:12:31 Let's make this as venv3.11 okay, I am opening a new cmd window.
-
00:12:37 You see it is started from here.
-
00:12:39 If I want to start it inside c drive, I am opening C drive inside this folder path typing
-
00:12:46 cmd and it is starting inside C drive.
-
00:12:49 Alternatively for navigation you can use cd...
-
00:12:53 It will go to one upper folder, cd...
-
00:12:56 It will go one parent folder like this and then type like this and it will generate a
-
00:13:03 new virtual environment with Python 11.3.
-
00:13:07 Okay, the environment is made.
-
00:13:10 So now I have my new environments folder inside my C drive.
-
00:13:14 Let's open it.
-
00:13:15 Open scripts.
-
00:13:16 Open as new cmd.
-
00:13:18 You see currently this is where I am type activate and now venv 3.11 is activated.
-
00:13:25 Let's type Python and you see this virtual environment is running with 3.11.3.
-
00:13:32 Whatever I install inside this virtual environment will not affect my other installations.
-
00:13:39 Let me demonstrate.
-
00:13:40 So I will install pillow package in this virtual environment.
-
00:13:45 For demonstration pip install pillow and then we will see whether this package is installed
-
00:13:51 in other installations or not.
-
00:13:53 Okay, now when I type pip uninstall pillow, it will ask me to uninstall it or not in this
-
00:13:59 installation.
-
00:14:00 Let's open another cmd window and let's type pip uninstall pillow and it will tell me that
-
00:14:06 pillow is not installed.
-
00:14:08 You see every virtual environment is completely separated and whatever you install in them
-
00:14:15 will be installed only in them.
-
00:14:18 You can also verify this by going into your virtual environment folder, library folders,
-
00:14:23 site packages folder.
-
00:14:25 Inside here you will see the installed libraries such as you see: pillow is installed in my
-
00:14:31 virtual environment 3.11 folder.
-
00:14:34 When I go to my original Python installation, inside lib, and inside site packages.
-
00:14:41 I won't see that particular library folder here.
-
00:14:46 Because it is not installed in my original Python installation or in my default Python
-
00:14:52 installation.
-
00:14:53 So every time to activate certain virtual environment, typing cmd inside that particular
-
00:14:59 folder, typing activate.
-
00:15:01 This is somewhat bothersome, taking some time so we can make a quick shortcut to achieve
-
00:15:08 this.
-
00:15:09 So I will make a shortcut in my documents folder.
-
00:15:11 Right click new text document.
-
00:15:14 Let's name it as start Python 3.11 venv.
-
00:15:17 This file currently has txt extension.
-
00:15:20 However we need to change it to .bat file.
-
00:15:25 To see the extension, go to views.
-
00:15:27 In here you will see file name extensions.
-
00:15:31 When you click it, it will show you the extension, and it will allow you to change it.
-
00:15:35 I will change it as bat like this.
-
00:15:37 Then I will right click and click edit here.
-
00:15:40 It will open the file.
-
00:15:42 Then this is the base script that we are going to use.
-
00:15:45 All we need to change is the folder where our virtual environment is installed.
-
00:15:51 To do that first I will enter inside my folder and I will click the navigation bar like this:
-
00:15:58 copy the path.
-
00:15:59 Paste it in here.
-
00:16:01 By the way, if you have spaces in your folder path then you should put quotation marks like
-
00:16:07 this to the beginning and end of the path.
-
00:16:10 Just save it.
-
00:16:11 Then when I double click this, start Python 3.11 venv bat file.
-
00:16:16 It will open cmd and it will start my virtual environment like this.
-
00:16:23 So that if you want to move into another folder and also start this virtual environment folder,
-
00:16:29 you can further modify this script.
-
00:16:33 So I want this secret to activate my virtual environment, then go to the this folder quickly
-
00:16:39 for me.
-
00:16:40 So I am typing this command under this call scripts bat file save it and when I start
-
00:16:48 my cmd window I see that the virtual environment is activated and current location of the cmd
-
00:16:55 is this folder.
-
00:16:56 When I type there, it will list me the directory content.
-
00:17:01 Then when I type Python I will see Python 3.11.3 is installed.
-
00:17:07 So this is the way of using virtual environments of Python: Lastly, I will show you How to
-
00:17:13 install Stable Diffusion Automatic1111 web UI.
-
00:17:17 To install it, copy the url of the GitHub repository, go to the folder where you want
-
00:17:23 to install.
-
00:17:24 I want to install the inside directly C drive.
-
00:17:26 This is also important.
-
00:17:27 You should directly install it inside your C or D drive.
-
00:17:30 It works best.
-
00:17:31 Type cmd.
-
00:17:33 Then we will use Git clone command.
-
00:17:35 We already installed Git.
-
00:17:37 Therefore, Git clone, paste the url with right click of your mouse or right click here and
-
00:17:43 from edit tab.
-
00:17:44 You can click paste or you can use ctrl v hit enter.
-
00:17:48 It will clone the entire repository into your current folder.
-
00:17:54 So the cloning has been done.
-
00:17:55 It downloaded all of the files actually over 17.000 files.
-
00:18:00 Okay in here now we see the cloned repository.
-
00:18:05 Automatic1111 web UI also generates its own virtual environment folder.
-
00:18:10 However, it will use your default Python installation.
-
00:18:14 So if you want to use certain Python installation then you need to change web ui-user .bat file.
-
00:18:20 Right click edit and in here you see set Python.
-
00:18:25 So you can set Python of any Python installation.
-
00:18:30 Let's set it as our 3.10.6 while hitting shift right click, copy as path in here, copy paste
-
00:18:39 it like this, and save.
-
00:18:42 So it will install everything with using this certain Python installation.
-
00:18:48 If I don't provide this, then it will install by using whatever the Python that you see
-
00:18:54 when you type Python to you a new cmd window.
-
00:18:58 Currently we are seeing the correct version.
-
00:19:00 However, if you had another default Python installation then it would use that one.
-
00:19:06 So like this and also let's set the --xformers.
-
00:19:10 These two are all the things that you need and it will download and install everything.
-
00:19:16 After saving, just double click and start the web ui-user.bat file.
-
00:19:20 You see it is using this Python exe.
-
00:19:22 It is creating new virtual environment.
-
00:19:25 It will download all of the necessary packages and install them and it will start the web
-
00:19:30 ui and you will be able to start using it.
-
00:19:32 This is all for today.
-
00:19:34 I have excellent tutorial videos on my channel for Stable Diffusion.
-
00:19:38 If you're interested in Stable Diffusion or ChatGPT or GPT4, please subscribe, like and
-
00:19:44 leave a comment.
-
00:19:45 Tell me what you want to see next.
-
00:19:47 Hopefully, I will make awesome further videos for ChatGPT or ChatGPT other alternatives,
-
00:19:53 open source alternatives.
-
00:19:55 Also, if you support me on Patreon and by joining our Youtube channel or leaving a super
-
00:20:01 thanks comment, I would appreciate that very much.
-
00:20:04 You can click the join button here to support me via Youtube.
-
00:20:08 You can click the support me on Patreon button and you can subscribe any of the membership
-
00:20:14 level.
-
00:20:15 I would appreciate that very much.
-
00:20:16 This is super important for me.
-
00:20:19 Also in the video description and in the comment section, you will see our Discord link and
-
00:20:23 Patreon link.
-
00:20:24 This is also extremely important.
-
00:20:27 You should join our Discord channel and communicate with other members.
-
00:20:31 Ask me any questions that you have.
-
00:20:34 Our Discord channel is also awesome.
-
00:20:36 I guarantee you that you will learn a lot of things from our Discord channel as well.
-
00:20:40 Also, our Discord channel is best way to contact with me.
-
00:20:44 You can also leave a comment and I am replying every one of the comments that you make.
-
00:20:49 I am giving super importance to your comments, your opinions, your feedback.
-
00:20:52 Hopefully see you in another awesome video.
