Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Start Setting Up Your Development Environment

Time to start setting up your development environment! The IDE you’ll see used in this course is PyCharm. This IDE has some advantages because it will perform some tasks for you automatically. For example, it creates a virtual environment when you start a new project. In this course, you’ll still see how to set one up by hand.

First head over to your terminal and make a new folder called django-portfolio by using the mkdir command. Then, move into the folder called django-portfolio and create a virtual environment with venv. You’ll use the command python 3 -m venv .env, where .env is the name of your virtual environment.

Before you can install any packages in there, you still need to activate the virtual environment. Run the command source .env/bin/activate. Your prompt will change, and you’ll be inside a virtual environment, so any changes you make will be limited to this environment. Then you can install django with pip.

Comments & Discussion

Pygator on Oct. 12, 2019

Do you know how to set the interpreter like that for VS code? I recently tried this IDE out and like the bundled terminal with it, but i also got into Sublime awhile back after Dan mentioned it’s awesomeness.

Martin Breuss RP Team on Oct. 16, 2019

There are a couple of great resources on VSCode here on Real Python. It’s definitely been gaining popularity and is quite similar to Sublime Text, if you’re already familiar with that one.

Kevin Walsh on Feb. 19, 2020

two questions: 1. can you create the virtual environment just using pycharm? or do i have to do it outside of pycharm and then import if needed? 2. when i start pycharm it shows python 3 with Django. Do i have to create the environment as shown or is it built in with Pycharm?

Martin Breuss RP Team on Feb. 21, 2020

Hi @Kevin Walsh. PyCharm can automatically create a venv for you when you start up a new project.

If you say New Project instead of Open you get to a dialog where you only need to click on Create and the virtual environment will be made for you by PyCharm.

Martin Breuss RP Team on Feb. 21, 2020

Also check out the walkthrough regarding that here in our PyCharm section of the Editor Course.

fredmord on Feb. 21, 2020

I am stuck with how I can set up pycharm environment.

Martin Breuss RP Team on Feb. 21, 2020

What are you stuck with @fredmord? Did you check out the resource I linked above? I’m happy to try to help, so please send me some more info so we can try to tackle the issue :)

tomkristensen0372 on Feb. 25, 2020

source .env/bin/activate. does not work in Windows. Does someone have a recommendation how we solve this in Windows 10 ? Thanks!

Geir Arne Hjelle RP Team on Feb. 25, 2020

Hi Tom, on Windows you should use something like the following instead:

C:\> venv\Scripts\activate.bat

Ref: realpython.com/get-started-with-django-1/#set-up-your-development-environment

Ricky White RP Team on Feb. 26, 2020

Hi Tom.

If you are using cmd (Command Prompt) then use Geir’s suggestion above. However, if you are using Powershell, the use activate.ps1 instead if activate.bat at the end of your path.

fredmord on Feb. 27, 2020

I am confused. don’t know either you are using mac or windows for your tutorials. I’m completely stuck on how to set up the environment. Do I have use the Terminal or Pycharm?

fredmord on Feb. 27, 2020

How do I create a virtual environment? Can’t I use pycharm to learn the tutorials?

Martin Breuss RP Team on Feb. 27, 2020

Hi @fredmord. There are different ways to get to the same goal, you can do it through your OS’s terminal or let PyCharm do the work.

For simplicity’s sake, I’d suggest you to use PyCharm. It automatically sets up a new virtual environment for you when you start a new project.

So just start a new project, verify that you can see the virtual environment folder as visible in the video I linked, and that when you open your PyCharm terminal, you can also see that the virtual environment is activated. This is also shown in the linked video.

Hope that helps! If you want to dive deeper and understand what virtual environments are about, why they are recommended to use, how to set them up etc., please check out the article on virtual environments that is also posted at the top of this page.

fredmord on Feb. 27, 2020

Okay, thank you. Then I will follow your video and use pycharm to learn.

fredmord on Feb. 27, 2020

At pycharm I chose new project from file menu and I selected Django

fredmord on Feb. 27, 2020

“projects can either be opened in a new window or replace the project in a existing window or be attached to the already opened projects.” “How would you like to open the project?” This Window. New Window. Attach. Cancel.

The above is what I found when I started iniated a new project from pycharm.

Thank you.

fredmord on Feb. 27, 2020

(venv) C:\Users\hp\PycharmProjects\untitled>

Please the above was what I found in my terminal.

Martin Breuss RP Team on Feb. 28, 2020

Looks okay @fredmord. Only thing is that it seems you didn’t input a name for your Django project, so it is called untitled.

You could try to make a new one and give it a name, e.g. django-porfolio and select to open it in This Window.

Your terminal prompt shows that PyCharm successfully created a virtual environment called venv for you and that it is activated:

(venv) C:\Users\hp\PycharmProjects\untitled>

^^ the (venv) part at the beginning indicates that all went well.

You can now install Django:

(venv) C:\Users\hp\PycharmProjects\untitled> pip install django

although it might already be installed, since you explicitly started a Django project with PyCharm, and therefore PyCharm might have already done also that for you.

In short: You’re good to go. :)

fredmord on Feb. 28, 2020

I am grateful sir.

Hi, when I tried to do

(.env) zhou@TJ-MacBook-Pro django-portfolio % pip install django

It showed the following message, I don’t know what to do to fix it.

/Users/zhou/Desktop/Personal-projects/django-portfolio/.env/bin/pip: line 2: /Users/zhou/Desktop/Personal Projects/django-portfolio/.env/bin/python3: No such file or directory
/Users/zhou/Desktop/Personal-projects/django-portfolio/.env/bin/pip: line 2: exec: /Users/zhou/Desktop/Personal Projects/django-portfolio/.env/bin/python3: cannot execute: No such file or directory

Martin Breuss RP Team on March 16, 2020

Hello @TJ, looks to me like you might have deleted your virtual environment?

Double check that the .env folder exists in your current directory and that it contains a bin/ folder that again contains the python3 executable.

The error message currently tells you that it can’t find the python3 executable, which is why the install command fails.

You can delete and re-create the virtual environment in case something is missing in there.

Bill Lafferty on May 21, 2020

Hi Martin,

When setting up the virtual environment, ‘python3’ is not recognized.

I’m on Windows 10, and am using Powershell through Anaconda. I referenced here for the setup.

Is it okay to use python -m venv .env instead? Or will that default to an older version of python?

Ricky White RP Team on May 21, 2020

Hi Bill.

The whole python3 thing is for UNIX based machine. In windows we have it a little easier, we just use the python command. This will use the default version of python. If you have several version installed on your machine, you can check the default version with python --version.

For your virtual env, you can use the python -m venv .env command without issue. Again it will use your default python version. Python 2 does not come pre-installed on windows as it does with UNIX operating systems, so we don’t have to deal with that incompatibility.

Hope that helps.

Bill Lafferty on May 21, 2020

Hi Ricky,

Worked, thanks! I’ve set up the venv, but am unable to activate it. I see above there is a thread about activation on Windows.

I tried the following line (changed the venv name to virtual_env because I’m a hopeless noob)

virtual_env\Scripts\activate.ps1

Which lead to a Fully Qualified Error ID: Could not auto load module.

REsearched it some more and found this instruction, just want to make sure I’m on track?

*On Microsoft Windows, it may be required to enable the Activate.ps1 script by setting the execution policy for the user. You can do this by issuing the following PowerShell command:

PS C:> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser*

Bill Lafferty on May 22, 2020

Hi all,

I’m unable to load the virtual environment. (Using Windows 10.)

  1. I created the django_portforlio folder as Martin instructed in the video
  2. Created ‘virtual_env’ (instead of venv)
  3. Set the Execution Policy to Unrestricted for CurrentUser, and then confirmed it using Get-ExecutionPolicy -List
  4. In djagno_portfolio, I tried virtual_env\Scripts\activate.ps1 and got error –> “virtual_env could not be loaded” (+ FullyQualifiedErrorId: CouldNotAutoLoadModule
  5. cd’d to the .virtual_env folder
  6. Tried virtual_env\Scripts\activate.ps1 again and got same error

NEXT STEP - Now that the ExecutionPolicy is unrestricted, should I start over from scratch?

NOTE - I’m signed in as admin in PowerShell

Thanks! Bill

Ricky White RP Team on May 22, 2020

Hi Bill. When you renamed the env did you do so by just changing the name of the folder? Or did you create it with your preferred name from the start? i.e. Did you type python -m venv virtual_env?

You shouldn’t need to adjust the privileges if it’s your own machine? Are you using a work/school computer?

Bill Lafferty on May 23, 2020

Hi Ricky,

I was on my work pc (had my manager’s blessing but didn’t have admin rights). Switched to my personal laptop and it works fine.

Thanks! Bill

Ricky White RP Team on May 24, 2020

Glad we got to the bottom of it :)

99janna on June 3, 2020

Hi Martin,

I’m using Atom on Mac. I was successfully able to get the folder created and go through all the steps to create the virtual environment. But I’ve gotten stuck now at the point where you have the terminal within your IDE displaying “(.env) martin@realpython$”, and Atom doesn’t have the same preferences to change like you did in the video. Is there an easy way to change the path within the terminal of Atom so that it also gives the (.env) path?

Thanks!!

Martin Breuss RP Team on June 3, 2020

Hi @99janna, to see that prompt you will need to activate the virtual environment that you created. You can do this in the same way as described in the video inside of the terminal that is included with VSCode.

You can acces the integrate terminal in VSCode by pulling up from the bottom of your window, or by using the menu items or shortcuts described in their official docs on the Integrated Terminal.

You can learn more in our VSCode Setup Guide and the associated video tutorial.

The command to activate your virtual environment is:

source <your_venv_name>/bin/activate

Hope that helps! :)

osintalex on June 20, 2020

Hi. For some reason I got a command not found error when trying to run django-admin.

I’m using zsh on Mac; I uninstalled Django with pip, installed again with sudo pip install django and it worked fine.

mathieu01 on July 11, 2020

Keep getting “System cannot find the path specified” on command prompt on windows when I try to activate. Any help please?

Become a Member to join the conversation.