Πώς να εγκαταστήσετε το Django στα Windows

This document will guide you through installing Python 3.8 and Django on Windows. It also provides instructions for setting up a virtual environment, which makes it easier to work on Python projects. This is meant as a beginner’s guide for users working on Django projects and does not reflect how Django should be installed when developing patches for Django itself.

The steps in this guide have been tested with Windows 10. In other versions, the steps would be similar. You will need to be familiar with using the Windows command prompt.

Εγκατάσταση Python

Django is a Python web framework, thus requiring Python to be installed on your machine. At the time of writing, Python 3.8 is the latest version.

To install Python on your machine go to https://python.org/downloads/. The website should offer you a download button for the latest Python version. Download the executable installer and run it. Check the boxes next to «Install launcher for all users (recommended)» then click «Install Now».

Μετά την εγκατάσταση, ανοίξτε μια γραμμή εντολών και ελέγξτε ότι η έκδοση Python που έχετε εγκατεστημένη ταιριάζει με αυτή που μόλις κατεβάσατε:

...\> py --version

Δείτε επίσης

For more details, see Using Python on Windows documentation.

Σχετικά με το pip

pip is a package manager for Python and is included by default with the Python installer. It helps to install and uninstall Python packages (such as Django!). For the rest of the installation, we’ll use pip to install Python packages from the command line.

Setting up a virtual environment

It is best practice to provide a dedicated environment for each Django project you create. There are many options to manage environments and packages within the Python ecosystem, some of which are recommended in the Python documentation. Python itself comes with venv for managing environments which we will use for this guide.

To create a virtual environment for your project, open a new command prompt, navigate to the folder where you want to create your project and then enter the following:

...\> py -m venv project-name

This will create a folder called “project-name” if it does not already exist and setup the virtual environment. To activate the environment, run:

...\> project-name\Scripts\activate.bat

The virtual environment will be activated and you’ll see «(project-name)» next to the command prompt to designate that. Each time you start a new command prompt, you’ll need to activate the environment again.

Εγκατάσταση Django

Το Django μπορεί να εγκατασταθεί εύκολα με το pip μέσα στο virtual environment που μόλις φτιάξατε.

Από την γραμμή εντολών, βεβαιωθείτε ότι το virtual environment σας είναι ενεργοποιημένο και εκτελέστε την ακόλουθη εντολή:

...\> py -m pip install Django

Η παραπάνω εντολή θα κατεβάσει και θα εγκαταστήσει την τελευταία έκδοση του Django. Αν θέλατε άλλη έκδοση και όχι την τελευταία, τότε θα γράφατε pip install django==x.x, όπου x.x η έκδοση που θέλετε να εγκαταστήσετε.

Αφού ολοκληρωθεί η εγκατάσταση, μπορείτε να επιβεβαιώσετε ότι εγκαταστάθηκε ορθά, εκτελώντας την εντολή django-admin --version μέσα από τη γραμμή εντολών.

Δείτε στο άρθρο See Get your database running αν θέλετε να χρησιμοποιήσετε κάποια βάση δεδομένων για το project σας.

Συνηθισμένα σφάλματα εγκατάστασης

  • Αν η εντολή django-admin εμφανίζει μόνο το βοηθητικό μήνυμα ανεξαρτήτως των παραμέτρων που δίνονται, τότε πιθανόν υπάρχει πρόβλημα στα Windows με το file association. Ελέγξτε αν υπάρχει παραπάνω από μια environment variable στο PATH, που να είναι ρυθμισμένη για να τρέχει Python scripts. Αυτό συνήθως συμβαίνει όταν είναι παραπάνω από μια εκδόσεις της Python εγκατεστημένες στο σύστημα σας.

  • If you are connecting to the internet behind a proxy, there might be problems in running the command py -m pip install Django. Set the environment variables for proxy configuration in the command prompt as follows:

    ...\> set http_proxy=http://username:password@proxyserver:proxyport
    ...\> set https_proxy=https://username:password@proxyserver:proxyport
    
Back to Top