Install Django for the first time

I started learning DJango for the first time. I have some basic python knowledge, but DJango is the first for me. I started from the django documentation page , but I'm stuck where it asks

python manage.py syncdb

I currently do not have a database, so I assumed that SQLite comes with django. Not sure how to move on? I also downloaded virtualenv-1.7.1.2 and installed it also with

python virtualenv.py ENV

I follow this video tutorial , he asks me to use

sudo pip install virtualenv

But when I write the above code, the output will be

sudo: pip: command not found

Help me!

+7
source share
4 answers

Do not use sudo with virtualenv . This is the easiest way to solve several problems.

Start by installing virtualenv - sudo apt-get install python-virtualenv

Then, as a regular user, run the following commands:

  • $ virtualenv --no-site-packages django-env
  • $ source django-env/bin/activate
  • (django-env)$ pip install django
  • (django-env)$ django-admin.py startproject myproject
  • (django-env)$ cd myproject
  • (django-env)/myproject$ nano settings.py
  • In settings.py , after 'ENGINE:' enter 'django.db.backends.sqlite3', (do not forget the comma)
  • In settings.py , after type 'NAME:' 'site.db', (again, don't forget the comma)
  • Save the file and exit the editor
  • (django-env)/myproject$ python manage.py syncdb
+22
source

Assuming you are using Linux, you should get Python setuptools from your distribution repositories. After installation, enter

 sudo easy_install pip # installs pip sudo pip install -U pip # upgrades pip to most recent version 

From there, you can continue to follow the manual.

If you are not using linux, download Python setuptools from PyPI. Python setuptools [PyPI]

For OS X, the above should still work in the terminal. In windows, you may need to do this from an elevated command prompt (not sure), but without the sudo at the beginning.

+2
source

SQLite is included in Python 2.5+. You should be able to edit the settings.py file with the appropriate database settings (database type and file name, see white papers for details), and your database will be created the next time you run syncdb.

There is a great tutorial on working with virtualenvs and Django at http://bartek.im/blog/2010/07/13/django-environment.html

I also recommend virtualenv-burrito to simplify the installation process (and updates) for virtualenv and virtualenvwrapper: https://github.com/brainsik/virtualenv-burrito

If you still run into problems, are you getting any errors when starting syncdb now? If so, what are they?

0
source

The most flexible way, IMO, to install without the old setuptools,

  • download virtualenv
    $ curl -O http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.7.1.2.tar.gz
  • extract
    tar xzf virtualenv-1.7.1.2.tar.gz
  • use the version of Python you want to run Django to install virtualenv like
    $ python2.7 virtualenv-1.7.1.2/virtualenv.py --distribute ~/env
  • type env in which the pip is already installed. $ source ~/env/bin/activate
  • install packages in current env instead of polluting global space or need sudo
    pip install Django
    Then Django will be installed on the path, for example ~/env/lib/python2.7/site-packages/django .
  • Or you can download pip install -e svn+http://code.djangoproject.com/svn/django/trunk
    to install the last Django connecting code, and the source will be in ~/env/src/django/django . Then you can read the source or change it. In addition, you may have full make html documents in ~/env/src/django/docs

The things set by the above method are completely local, you do not need to enter sudo or risk tangled paths like /usr/local/lib , especially since you could install several versions of Django or Python does not affect each other!

Alternatively, you can try virtualenvwrapper.

0
source

All Articles