How to start a Django project using virtualenv?

3

I have already tried and found different ways and different conventions for creating a project in Django using virtual environment (virtualenv). Is there any standard for this? Does anyone help me with a correct step by step?

Using python 2.7 + Django 1.8

    
asked by anonymous 15.09.2015 / 04:23

3 answers

1

Considering that you already have pip installed, to use the isolated environments approach is very simple, even more so with virtualenvwrapper. The virtualenvwrapper is, as the name already indicates, a wrapper for virtualenv, with commands that make it easier to use its functions.

pip install virtualenvwrapper

If you have not installed virtualenv before, the above command will do this for you.

After that, to create a new environment is very simple:

mkvirtualenv nome_da_env

When you're finished, your env will be created, and if you've done it correctly virtualenvwrapper configuration (in case of using a Unix-like OS), your env will already be activated. To disable just run the command:

deactivate

And to enable, or change environment:

workon nome_da_env

In short: install virtalenvwrapper, set it as quoted in the link above, and use these commands to make your life easier.

    
15.09.2015 / 05:37
0

I often use the generator-django for Yeoman.

To install it use the command below:

npm install -g generator-django

Create virtualenv and enable it:

virtualenv myproject --no-site-packages
source myproject/bin/activate

Now create the project directory and run the Yeoman generator:

mkdir myproject && cd myproject
yo django

More details on installing the project documentation .

    
15.09.2015 / 04:29
0
  

I have already tried and found different ways and different conventions for   creating a project in Django using virtual environment   (virtualenv).

Creating a project in Django has no relation to virtualenv, I do not know if the question was poorly formulated, but creating the project depends only on having Django, having no dependence on the environment. Virtualenv is just a tool for creating isolated environments.

So, just having Django installed on the machine or the virtualenv environment, you can create your project using django-admin startproject meuprojeto , this is the default, installing any other package to do this is redundant.

Maybe your question is:

How to create an isolated environment and how to start the environment?

In MacOSX I do this:

iMac:~ Orion$: pip install virtualenv, virtualenvwrapper

In the .profile file I add the references responsible for running virtualenvwrapper (storing in the file you are sure to restart the computer when the variables are reloaded):

export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

To create an environment (creating it already activates the environment):

iMac:~ Orion$: mkvirtualenv ambiente_teste

To disable:

(ambiente_teste)iMac:~ Orion$: deactivate

To reactivate (using workon ):

iMac:~ Orion$: workon ambiente_teste

And to create a project (make sure you are creating the project in the desired directory):

(ambiente_teste)iMac:~ Orion$: django-admin startproject meuprojeto
    
15.09.2015 / 07:31