How to Create a Django Project in Anaconda Very Easily


Let’s see how we can create a Django project when you are using Anaconda as your default Python. We do this process by creating a new environment.  

Anaconda is a free and open-source distribution of the Python programming language for scientific computing, that helps to simplify package management and deployment. I highly recommend you to use Anaconda for your Python projects, if you are not using it already. Anaconda software makes life very easy.

I have been doing projects in Django for a while. A few weeks ago, I installed Anaconda for machine learning studies and made it my default Python. Then I was back to doing my Django projects but my CMD was not able to run Django using the commands that I have been using previously.  

To solve these issues, I did some research over the Internet, but couldn’t find the right solution either from YouTube and Google. Finally, I got the solution after trying various things. So if you are dealing with such a situation, this article may help you.

If you are using a Windows operating system, follow along with this tutorial. I think the procedure is very similar in Mac and Linux too. So, you can follow along with this article even if you are not using Windows.  

How to Create a Django Project in Anaconda Very Easily

How To Create A Django Project In Anaconda?

Here are the steps that you need to follow to create a Django project in anaconda:

1. Create a new environment

First of all, you need to create a separate environment for Django development.  

By default, anaconda comes up with the base environment. But creating a separate environment will be helpful to manage the projects without any package dependency confliction.   

So, let’s create a separate environment specifically for web development projects using the Django framework.  

Open your CMD or Anaconda Prompt and create a separate environment called djangoenv by typing in the following command.

conda create -n djangoenv python=3.6 anaconda    

I just mentioned the version of Python that I’m using as Python 3.6. If you want to use other versions of Python, you can do so.  

The previous command may take some time to finish its execution. Once it is done, let’s go to the next step.

2. Activate the new environment

Activate the newly created environment by typing in the following command.

conda activate djangoenv

Now, we are inside the newly created environment. But our environment does not have Django in it. So, let’s install it.

3. Install Django in the new environment

Let’s install Django in the new environment using the following command. 

conda install -c anaconda django 

Wait till the installation completes. It may take some time to finish. That’s it. Now you can create Django projects in this separate environment.  

Let’s try to create a sample project to check whether everything is ready. Let’s do this using the following commands.  

4. Create a new Django project

First of all, let’s start a new project called website.

django-admin startproject website 

5. Run the Django server

Now, navigate to the project folder by using the cd command. Let’s run the project and see whether everything is working fine or not.

python manage.py runserver 

If you are on a Mac or Linux, use python3 manage.py runserver instead of the command given above.  

Once you’ve done that, a URL will be generated on the command line. Now, copy the URL that is generated and paste it on a new tab in your browser.  

That’s it. Everything is set up nicely if you can see this rocket launching up towards the sky.  

Django project in anaconda

Your Django environment is ready. After this, you can open Command Prompt or Anaconda Prompt whenever needed, and start doing the project just by activating the environment for Django.  

The following command is used whenever we need to activate the Django environment.

conda activate djangoenv 

Do these steps and create stunning projects using your favorite backend web framework “Django”, without changing your Anaconda setup.  

What if Anaconda does not work?

If you have any trouble using the Anaconda software, then there is an alternative option available for you. This software is called Miniconda, which is a lightweight version of Anaconda. 

Miniconda is a software from the Anaconda family itself. They made this light version for people having problems using the big fat Anaconda software. I had a lot of problems using Anaconda at times.

So, I switched to Miniconda software. The only problem is that you will not get the Anaconda user interface in Miniconda. But, if you are comfortable using the command line, you can use this software since it provides the Anaconda prompt. 

It is always better to use this software for your Python projects rather than using your default Python software. You can install Miniconda by going to their website.

Creating Django Projects

Doing projects is the most important thing that you can do to become a better developer. If you learn the entire syntax of Python and Django and never do a project, then there is no point in your learning.

Django is a difficult framework to learn, especially for absolute beginners. You should get a feel for the framework by doing projects and exercises.

At first, it may seem overwhelming. But after you do some projects, you will figure out a process that can be repeatable. If you can stay motivated and figure out a way to do many projects in Django, you can become a back-end web developer or even a full-stack web developer.

Also, doing a portfolio of amazing projects will increase your chances of landing your dream job. I recommend you create a portfolio of projects so that you can display all the work that you have done at a single location.

It is a good practice to upload your code to GitHub or other coding repositories after you’ve finished each project.

If you are interested in creating projects in Django, but you don’t know what to create, then I have a resource for you. I’ve written an article on 12 Django Project Ideas for Beginners, which you can steal right away and implement. Oh, by the way, I’ve added some tutorials along with each idea to help you. Make sure you check it out.

I hope this article would be helpful for you in some way. If you encounter any issues or doubts, please feel free to ask them in the comments section. I will be happy to help you. Also, share this article with your friends so that it will be helpful to them as well.

Happy coding!

Ashwin Joy

I'm the face behind Pythonista Planet. I learned my first programming language back in 2015. Ever since then, I've been learning programming and immersing myself in technology. On this site, I share everything that I've learned about computer programming.

64 thoughts on “How to Create a Django Project in Anaconda Very Easily

    1. Hi Dharmender,

      If you want to install sqlparse, you can use the following command: conda install -c anaconda sqlparse

      Thank you.

  1. Very helpful. Thanks for sharing these instructions!

    I had some difficulty using the conda activate command.

    If other’s encounter this issue in Windows CMD, try:
    set PATH=%PATH%;\Scripts
    activate djangoenv

    Also if you are using git bash, try:
    source activate djangoenv

  2. Sir, This is a great tutorial for beginners. But here is some issue, when I run the “python manage.py runserver” command, it throws an error “can’t open the file [Err No 2] no such file or directory” What to do for this? I looked into the directory, It created the directory by itself but not running.

    1. I think you are not inside the project directory. In the example that I mentioned above, you need to be in the directory called ‘website’ to run this command. So, after you type in django-admin startproject website command, type in cd website. Then type in the python manage.py runserver command. Hopefully, this will solve the issue.

  3. Hello, thank you for the tutorial, I really appreciate your hard work. I just need help pls, I found an HTTP error when i tried to create the env ( I typed conda create -n djangoenv python=3.6 anaconda)
    then I found this error:
    CondaHTTPError: HTTP 000 CONNECTION FAILED for url
    Elapsed: –

    An HTTP error occurred when trying to retrieve this URL.
    HTTP errors are often intermittent, and a simple retry will get you on your way.

    CondaHTTPError: HTTP 000 CONNECTION FAILED for url
    Elapsed: –

    An HTTP error occurred when trying to retrieve this URL.
    HTTP errors are often intermittent, and a simple retry will get you on your way.

    CondaHTTPError: HTTP 000 CONNECTION FAILED for url
    Elapsed: –

    An HTTP error occurred when trying to retrieve this URL.
    HTTP errors are often intermittent, and a simple retry will get you on your way.

    CondaHTTPError: HTTP 000 CONNECTION FAILED for url
    Elapsed: –

    An HTTP error occurred when trying to retrieve this URL.
    HTTP errors are often intermittent, and a simple retry will get you on your way.

    1. Just try running the following command: conda config –set ssl_verify no

      and try again to create conda environment. Hopefully it will solve the issue.

  4. Hello is, does spyder support django project? if Yes, kindly tell me the full procedure. thanks for this article which you write about how to install Django with anaconda.

    Regard
    Muhammad Shams Paracha
    waiting to your response

    1. Yes, you can create Django projects with spyder. In fact, Anaconda navigator has spyder IDE built into it. If you have Anaconda, you can use that. If you’re using python without Anaconda, go to your command line and install Django through pip (pip install django). Then you can install spyder IDE and work with it. Thanks for your comment.

  5. Hi,

    I have a HTML page in my python django application.
    I have a folder named “media” which contains the images that I’m trying to use in my html page, I’m not able to display the images.

    Should I just paste the relative path in the tag or should I do any other setting?
    Could you please help?

    Thanks

    1. 1. Add the following line to the top of your HTML page: {% load static %}
      2. Add an img tag wherever you want to place the image and give the relative path as src.

      For example,

      img src=”{% static ‘../static/code.jpg’ %}” alt=”my_image”

      For me, the HTML file was in the templates folder and my image is in static folder. That’s why I gave a path like that. You can give the correct path according to your file structures.

      If you can’t, just put the image in the folder where your HTML page is, and use the following tag:

      img src=”{% static ‘image.jpg’ %}”

      I hope that helps.

  6. I was able to install Django over Anaconda and even activate the django environment. However when I gave the command Django-admin startproject myproj I get an error saying django-admin is not recognized an internal or external command. I tried to run anaconda django command screen as administrator but still, it did not work. If I need to make changes in the environment variables how do I do it?

    1. Just a correction, the command I gave was correct django-admin startproject myproj – the spelling was correct.

      1. Just type in ‘django’ in your environment and see what comes up. If ‘django’ is not recognized as an internal or external command, operable program or batch file, then try to install it using pip install django command.

        If Django is already there, then uninstall it using pip uninstall django and then install it again using pip install django. I’m not sure whether it’ll fix it or not, but just give it a try. Hopefully, it’ll fix the issue.

          1. hi ashwin i am getting ‘python : can’t open file’manage.py’:[error 2 ] no such file or directory .after typing the same command that you gave as” python manage.py runserver.
            please help me out ………

          2. I think you’re not inside the correct directory. Go to the correct directory using the cd command and then execute the command.

    1. Maybe you can. I’m not sure though. I’m currently using Miniconda, which does not have the Anaconda navigator GUI.

  7. hi ashwin ,thanks for answering earlier but i am still facing issues , after using python manage.py runserver command i got ” starting development server at http://127.0.0.1:8000/” but i am not getting welcome page after putting it on use .

    1. Do you use this port(8000) for other purposes? If so, try changing the port: https://pythonistaplanet.com/how-to-change-the-default-runserver-port-in-django/

  8. i was searching the whole internet for this. found ours after 2 hours of trying to install. thank you for this <3

  9. Hello,
    You say: conda install -c anaconda django

    How conda knows where is my installation of the django?

    1. The installation will be on the directory that you’re currently in when you’re using the Anaconda prompt.

  10. python: can’t open file ‘manage.py’: [Errno 2] No such file or directory
    im getting this error i change the path to C:\ProgramData\Anaconda3> but im getting same error

  11. Hi Ashwin,
    Thanks for the tutorial, I find it very useful.
    After python manage.py runserver I got the errot below:

    System check identified no issues (0 silenced).
    July 06, 2020 – 22:50:43
    Django version 3.0.3, using settings ‘website.settings’
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CTRL-BREAK.
    Error: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

    Any idea where does this problem come from?
    Many thanks.

    1. I don’t have much idea about this error. Seems like an OS error. Please google the error and find out what StackOverflow or other communities are saying about it. Hopefully, you’ll be able to fix it.

      Thank you 🙂

  12. can i use anaconda now in 2020 or its just a old way to create projects using anaconda can u tell me why we use anaconda in django

  13. Hi Ashwin,
    Thanks for this tutorial. Found it very useful. After starting the django development server I am getting a warning like this :

    You have 17 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
    Run ‘python manage.py migrate’ to apply them.

    It would be great if u can help to correct this

    Thanks
    Sowmya

  14. Nice simple tutorial. Quick question, if I would like to save my environment and push it to github, then in another computer download the repository and restore the environment what do I do? eg. the pip way would be pip freeze into a file which you install in the new environment. THanks!

  15. Thanks for the tutorial, helped me a lot.
    Just one note, at the installation part, we can just run
    $conda create -n djangoenv python=3.6
    without “anaconda” at the end, that way the install time is really quick as it doesn’t download all the libraries for anaconda.

  16. hey aswin,
    i installed django as you said but whenever i try to run a simple hello world program

    i got ,

    Exception has occurred: ImportError
    attempted relative import with no known parent package
    File “C:\Users\ajhbcadjk\urls.py”, line 2, in
    from . import views

    1. I think there’s something wrong with the path. Do a google search of this error and check StackOverflow. Hopefully, you’ll get a solution.

  17. Sir i have created the website and the app but whenever I link it in the urls.py of app module it doesn’t do this line:
    from . import views
    always show module cant be found

  18. Hi sir, I have completed my M.C.A., but I lack skills. Although I touched some code during the six months after graduating, I couldn’t secure a job. Now, I’ve set my goal to become a Python developer. As a Python developer, I need to have knowledge of backend development, so I want to learn Django. However, I’m unsure about which source to choose. Can you give me some ideas and recommend a low-cost Django course on Udemy or another platform?

    1. You can find plenty of free videos on YouTube. Check out videos made by CodingEntrepreneurs or any other YT channel.

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts