Python Environment - venv & Docker (locally and GitHub)
Introduction
The video introduces the topic of installing Docker and Visual Studio Code for Windows.
Installing Docker
- To install Docker, go to docker.com and click on "Download Docker Desktop for Windows."
- Open the executable file to start the installation of Docker.
- This installation will require restarting your computer.
- After the installation, click on "Close and Restart." This action will restart your computer.
- If you currently don't have WSL kernel installed, you have to install it now. Go to the link in the message box; it will open a website with instructions on how to install it.
- Click on this link to download WSL. When the file is downloaded, execute it and follow these steps.
- When the installation is complete, you have to close Docker and restart it so that changes take effect.
Installing Visual Studio Code
- To install Visual Studio Code, go to this website and download it for Windows.
- Execute the downloaded file and follow these steps. Let's keep the default settings and press next and then install.
- To use Visual Studio with a Docker container, you have to add the extension Dev containers by clicking on "Install."
Creating a Python Environment
The video explains how to create a Python environment using Docker.
Creating an Environment for Python
- Go back to our Docker container to create our environment for python. Click "Get Started" and then check local directory. Please give it a name and click select to specify the path for your local directory. Select the folder and press continue depending on where the folder you want
to use is located; it will require you to open Docker as administrator.
- If you get an error when trying to create a Dev environment using a local directory, try running Docker as administrator.
- When the environment is complete, press "Done" or go directly and click "Open in VS Code" to open Visual Studio Code.
Using Visual Studio Code
- Now that our environment is attached to our local Dev folder, we can create files in VS Code, and the files will be available in both places: the Docker environment and your local folder.
- VS Code will prompt some recommendations about installing extensions like Python. I also recommend installing each recommended extension.
Running Python Code
The video explains how to run Python code using Docker.
Checking the System
- Let's run
apt-get updateto get the system up-to-date.
- Your development environment is isolated from your operating system. If we run the command
uname -a, we will see the details of the operating system where our python environment is running.
Installing PIP
- One library that we used for installing other libraries is PIP. To use it, we need to install it by running the following command:
apt-get install python3-pip
- To check the version, run
pip3 --version.
Running a Simple Print Code
- Now let's run a simple print code to ensure we can run python code:
print("Hello World!")
Using GitHub Repository with Docker Dev Environment
The video explains how to use GitHub repository with Docker Dev Environment.
Creating a GitHub Repository
- You can use Docker Dev Environment with GitHub repository. To create it, click on "Create" button, then "Get Started," and give it a name.
- You need a GitHub account to use them with Docker Dev Environment. You can sign in or create an account. If you do not already have an account, create a repository if you still don't have one and copy the repo link.
- Press "Continue."
Installing Git
- If you get an error like this, that means you still don't have Git on your computer. So let's install it. Click on "Install" to open this website, find the Windows version of the setup, and click on the link.
- Execute the downloaded file and install Git. Click on next and keep the default settings.
Creating a New File and Synchronizing with GitHub
This section covers how to create a new file in Visual Studio Code and synchronize it with GitHub.
Steps for Synchronization
- Click on the get icon to commit your files into GitHub using Visual Studio.
- Click on the plus icon to stage your file.
- Give the commit a short description and click the commit button.
- If this is the first time you are doing this, you will need to configure your username and email. Execute the following commands using your username and email that you used when you created your GitHub account.
- If there are no stage changes, delete the composed Dev file that was generated during dev environment creation.
- If you don't see your file in GitHub repository, execute this command: "git push -u origin main".
Setting Up Python Virtual Environment
This section covers how to set up a virtual environment for Python development.
Installing Python
- Go to the python website and download the latest version of python.
- Check on "add python to path" before starting installation.
Setting Up Virtual Environment
- Create a folder for virtual environment installation.
- Run command "python -m venv env_name" (replace env_name with desired name).
- Activate virtual environment by running "env_nameScriptsactivate".
- Install any package or library in this particular environment.
Enabling Scripts Running in Powershell
This section covers how to enable scripts running in Powershell if they have been disabled.
Steps for Enabling Scripts Running
- Copy link from error message indicating that scripts cannot be loaded because running scripts is disabled on system.
- Open link in browser where instructions will appear on how to enable scripts running in Powershell.
- Scroll down and copy command to enable scripts running in Powershell.
- Run the command in your terminal or directly in your Powershell command prompt.
Green Name Error
In this section, the speaker explains what the "green name" error means and how to fix it.
Understanding the Green Name Error
- The green name error indicates that you are outside of your virtual environment.
- This means that if you try to run a command that requires a library installed in your virtual environment, it will not work.
Fixing the Green Name Error
- To fix the green name error, you need to activate your virtual environment.
- Once activated, you can rerun the freeze command to see which libraries are installed in your virtual environment.
Turn any video into a summary like this
YouTube links, meetings, lectures. With transcripts, search, and chat.