Installing Wagtail using venv

This video is from Wagtail CMS 2023 .

Installing Wagtail using venv
0:04:53
Published November 29, 2023
2,589 views

This is a clip from the official Wagtail for Beginners Course (different from the Learn Wagtail course)
https://learnwagtail.com/wagtail-for-beginners/

There are a lot of ways to setup a Python virtual environment. Virtual environments are layer between your computer and your project that helps you avoid pathing issue, package version issues, and gives you a dedicated environment for your project. It's HIGHLY recommended you use some form of virtual environment.

To create a new venv using Python, simply type:
python -m venv yourvenvname

The Wagtail for Beginners course is a guided Wagtail course for brand new Wagtail developers. You'll create Wagtail pages, menus, orderables, and much more. And then you'll launch your website on your own dedicated Ubuntu server.
https://learnwagtail.com/wagtail-for-beginners/

#Wagtail #Django #Python

Summary

The speaker demonstrates installing Wagtail 2.7 in a Python virtual environment using Python 3.7.2. They create a project directory and virtual environment, activate it, install Wagtail, and use `pip show` and `pip freeze` to inspect the installed packages. They then create the Wagtail project in the current directory, install its requirements, run the development server, apply the database migrations with `python manage.py migrate`, and confirm the site loads at localhost:8000. The speaker also explains that separate virtual environments can use different Wagtail versions without conflicts and shows that `deactivate` exits the environment.

Key takeaways

  • Create and activate a virtual environment with `python -m venv` and `source <environment>/bin/activate`.
  • Install Wagtail with pip and inspect the environment using `pip show` and `pip freeze`.
  • Use `wagtail start` with the current-directory option to create the project without adding another nested folder.
  • Run `python manage.py migrate` before loading the site to create the required database tables.
  • Exit the virtual environment with `deactivate`, and use separate environments to avoid dependency conflicts.

Summarised automatically from the transcript.

Transcript

870 words · auto-generated Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:00

Alright, we are going to install Wagtail using Venv, VNV. So I already have Python running, and you can see I'm running Python 3. 7. 2. So I'm going to do Python-m venv And then the name of whatever virtual environment I want to call. I'm gonna call this Rocketman Venv. Actually, what I'm going to do is create a new directory first. So let's cancel that and let's do mkdiar. Rocketman. C D Rocketman and you can see my working directory here. So I'm in users, Caleb Tallinn, Websites Rocketman, and now I'm going to do Python-m venv rocketman venv. The name is not really important, it's just your virtual environment. So I'm going to call it rocketman

0:46

venv, and we're going to see it's going to create a new directory for me here. So let's do an ls-la, and we can see that there is a folder in here called rocketman venv. Right in there To get into this thing, all we have to do is type source, rockamanvenv, bin, activate, which if this is your first time that's going to look really weird, but you know, after a little while you get used to it. and I am now inside of this virtual environment. And you can see that cause it says Rocketman Venv in brackets to the left of my user So now at this point I can do pip V. We can see I'm using pip 18. 1. It's coming from My virtual environment, that's the folder here, that's the directory, Python 3. 7. So that all looks good. Let's go ahead and install Wagtail now. So pip

1:31

install Wagtail. Alright, so Wagtail has been installed. I can now do pip show Wagtail. It shows me that I'm using Wagtail version 2. 7. Right there. I can also do pip freeze to see all of my packages that are installed in this virtual environment. So I've got BeautifulSoup, Certify, Django, Django TreeBeard, HML5lib. Pillow, requests, 6, URL lib, wagtail, willow, all sorts of stuff. So that's what is installed in my virtual environment. My computer does not have access to that unless I'm inside of that virtual environment. Now I'm able to say that this project is going to run Wagtail 2. 7, and in another virtual environment I can say, hey, use Wagtail 2. 4. Use an older version of Wagtail, use Wagtail 1.

2:18

13 if we wanted to. And these will never conflict with each other, which is really, really nice. So now what we need to do is Wagtail, Start, MySite. And that's going to create a website called my site. I don't want it to be called my site. I'm going to be c making a website called Rocketman. So I'm going to do Wegtail Start Rocketman. That's going to create a new folder called Rocketman, but I don't want it to do that. I want it to create a new project, a new Wagtail website in the directory that I'm in. I'm already in a directory called Rocketman. I've got a virtual env in here and I want to create this new project in this directory. So let's go ahead and do that. You can see that that was very fast. ls -la and we now have Docker file, home folder, managed. py, requirements. txt , Rocketman folder, that's where our settings and static files and templates are going to go.

3:06

We've got a search app and we've got our virtual environment So now we can do pip install dash r requirements dot txt and All of that, it looks like it's already been satisfied to some degree. And now to run our server, we just type python manage. py run server 0. 0. 08000 And it should say this. You should see this alarming red text saying you have 89 unapplied migrations. And if we were to open up our browser. And head on over to localhost port 8000. We're going to see this error. That's actually a good thing. That means your website is up and running. So I just canceled my server there with

3:52

control C. That 'll just cancel your server so it doesn't run anymore. And next we need to provision our database because if we Skip back over to where this error is showing up on localhost 8000. We're gonna see it says no such table wagtail core site Well a table is a database term. This is looking for a database that's set up in a specific way to get started, and it's not set up that way. So let's go ahead and set that up the proper way. So let's do Python manage. py migrate. And we'll see this is going to apply all these different files. And then If we rerun our server with Python manage. py run server 00008000, let's go back here and refresh our page. Voila! We have Wagtail installed using

4:38

VNV or Venv. And then to get out of your virtual environment, you just have to type the word deactivate. You can see that down here. Sorry, that's at the bottom. But yeah, you just type the word deactivate and that Rocketman Venv seems to go away.

Questions this talk answers

How do I install Wagtail in a Python virtual environment?

Create a project directory, run `python -m venv` to create the environment, activate it with `source <venv>/bin/activate`, and install Wagtail with `pip install Wagtail`.

Discussed at 0:00

How do I create a Wagtail project in the directory I’m already in?

Run `wagtail start <project-name> .` so Wagtail creates the project files in the current directory rather than making another nested directory. Then install the project requirements with `pip install -r requirements.txt`.

Discussed at 2:18

How do I fix the “no such table wagtailcore_site” error in a new Wagtail project?

Apply the database migrations with `python manage.py migrate`, then restart the development server and refresh the site.

Discussed at 3:52

How do I exit a Python virtual environment?

Run `deactivate`; the virtual environment name will disappear from the shell prompt.

Discussed at 4:38

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos from Wagtail CMS