Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to start a new project in django using virtualenv

I just installed virtualenv and in it I installed django. However, when I go to the django-admin terminal in the bin file, I wrote

django-admin startproject mysite 

I thought that would start a new project but it just returned

Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.).

like image 562
Daniel dos Santos Avatar asked Oct 21 '18 16:10

Daniel dos Santos


People also ask

What is the command to start a new Django project called my project?

$ django-admin startproject myproject .

Why do we create virtual environment in Django?

A virtual environment is a tool that helps to keep dependencies required by different projects separate by creating isolated python virtual environments for them. This is one of the most important tools that most of the Python developers use.


2 Answers

Here is how to start a new django project in a virtualenv:

1. Create a new virtualenv for your project:

virtualenv py_env --python=python3

--python=python3 is not mandatory. I'd recommend programming in python3.x but this is up to you. If you are unsure about what is the default python that will be used when omitting the --python option, type python -V in your terminal.

2. Activate the virtualenv:

source py_env/bin/activate

If you see a (py_env) at the beginning of the command line, then you know the virtualenv is activated. To deactivate, simply type deactivate.

3. Install the required packages:

pip install django

While this is not needed, I recommend using ipython, so you might want to run pip install ipython.

4. Create a new django project:

django-admin startproject mysite

Hope that helped and happy coding!

like image 109
jojo Avatar answered Sep 26 '22 17:09

jojo


I think you should first make a virtual environment:

pip3 install --user pipenv

Make a virtual environment:

pipenv --python 3.6

Activate the environment:

pipenv shell

and after this do whatever you want i think it would work better now

Pipenv is best to use because it brings the best Packages of python so that there may not be further bugs while making the virtual environment. And django can be replicated properly.

like image 37
Raied Khan Avatar answered Sep 24 '22 17:09

Raied Khan