-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython_django_set-custom
More file actions
248 lines (198 loc) · 9.11 KB
/
Copy pathpython_django_set-custom
File metadata and controls
248 lines (198 loc) · 9.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
### python-django custom params ###
## while in idle / idle3
#http://stackoverflow.com/questions/3132265/how-do-i-access-the-command-history-from-idle
# recall commands :
# ->last / previous = ALT+p
# ->next = ALT+n
### django installation
## where to start - online guides
#https://docs.djangoproject.com/en/dev/intro/tutorial01/#writing-your-first-django-app-part-1
## installation guides / instructions (can be reached from the link above)
# https://docs.djangoproject.com/en/dev/topics/install/#install-the-django-code
# https://docs.djangoproject.com/en/dev/intro/contributing/
## check version -> if django is already installed
$ python -c "import django; print(django.get_version())"
# or enter into python prompt
$ python3
>>> import django
>>> print(django.get_version())
>>> (Ctrl+D)
## uninstall previous version
# if previously installed with pip, version upgrading and uninstalling is managed with pip
# otherwise find django folder and remove it manually
$ python3 -c "import django; print(django.__path__)"
## installation : virtualenv pip
$ mkdir ~/.virtualenvs
$ sudo apt-get install python3-venv
# in case of "E: Unable to locate package python3-venv"
# verify the package version and try the corresponding
$ sudo apt-get install python3.X-venv
$ python3 -m venv ~/.virtualenvs/djangodev
## in case the command above fails follow the steps below :
# install pip3
$ sudo apt-get install python3-pip
$ sudo pip3 install virtualenv
$ virtualenv --python=`which python3` ~/.virtualenvs/djangodev
## activate virtualenv whenever a new terminal is launched
$ source ~/.virtualenvs/djangodev/bin/activate
# add this line in file .bashrc to create alias
alias djactivate='source ~/.virtualenvs/djangodev/bin/activate'
# and resfresh bash or restart terminal
$ . ~/.bashrc
## -> if virtualenv isn't activated, django installs systemwide
$ git clone https://github.com/django/django.git
(djangodev) $ sudo pip3 install -e /path/to/your/local/clone/django/
## after install recheck the version
(djangodev) $ django-admin.py --version
1.11.dev20160612013256
## check paragraph "Where should this code live"
# https://docs.djangoproject.com/en/dev/intro/tutorial01/#creating-a-project
$ sudo mkdir /home/firstimedjango/
$ cd /home/firstimedjango/
# folder 'firstimedjango' needs a user ownership if located out of ~
# otherwise the command django-admin fails
$ sudo chown -R user /home/firstimedjango
## start a new project
$ django-admin startproject djprojone
## \!/ remember -> to avoid possible malfunctioning and timeloss on error searching \!/
# - previously started project out of virtualenv might become unresposive while later activated in virtualenv
# - don't forget to set the ownership of the location where code resides (runserver command will not start the server properly)
# Install PostgreSQL, PostGIS, pgadmin, pgrouting, contrib, other subpackages & libraries
# PostgreSQL
## database installation PostgreSQL
# installing a default ubuntu version
# postgresql-$VERSION=9.5
$ apt-get install postgresql-$VERSION
# installing another/latest version via PostgreSQL Apt Repository
# create pgdg.list
$ sudo touch /etc/apt/sources.list.d/pgdg.list
# add the repository for your current ubuntu release
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# import the repository key
sudo apt-get install wget ca-certificates
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# update repository
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install postgresql-$VERSION
# Install includes subpackages :
# "contrib" - provides additional supplied modules like "fuzzystrmatch"
# pgrouting"
# In case they are not provided within the install they will be probably a missing option with GeoDjango
#$ sudo apt-get install postgresql-contrib-9.5 postgresql-9.5-pgrouting
# UGI for db administration if needed :
$ sudo apt-get install pgadmin3
info extracted from :
http://postgis.net/install/
https://www.postgresql.org/download/linux/ubuntu/
http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS22UbuntuPGSQL95Apt
https://wiki.postgresql.org/wiki/Apt
# Geospatial libraries are recommended / required to run GeoDjango with corresponding spatial database ~ PostGIS
# requirements table : https://docs.djangoproject.com/en/1.9/ref/contrib/gis/install/geolibs/#installing-geospatial-libraries
# comparison matrix : https://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQLPostGIS
# binutils - GNU assembler, linker and binary utilities /Python needs find_library routine
#may be already on system
# libproj-dev - Cartographic projection library (development files)
# gdal-bin - Geospatial Data Abstraction Library - Utility programs /for GDAL command line programs like ogr2ogr
#may be already on system
$ sudo apt-get install binutils libproj-dev gdal-bin
# libgeoip1 - non-DNS IP-to-country resolver library /for GeoIP support
# python-gdal - Python bindings to the Geospatial Data Abstraction Library /for GDAL’s own Python bindings - includes interfaces for raster manipulation
# GEOS - refer to https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/geolibs/#geos
# geos-$VERSION.tar.bz2=3.5.0
$ wget http://download.osgeo.org/geos/geos-$VERSION.tar.bz2
$ tar xjf geos-$VERSION.tar.bz2
$ cd geos-$VERSION
$ ./configure
$ make
$ sudo make install
$ sudo ldconfig
$ cd ..
# PROJ.4 - geospatial data converter for differen coordinate reference systems
# https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/geolibs/#proj4
# proj-$VERSION.tar.gz=4.9.2 # proj-datumgrid-$VERSION.tar.gz=1.5
$ wget http://download.osgeo.org/proj/proj-$VERSION.tar.gz
$ wget http://download.osgeo.org/proj/proj-datumgrid-$VERSION.tar.gz
$ tar xzf proj-$VERSION.tar.gz
# important! decompress contents of proj-datumgrid into proj-$VERSION/nad directory
$ cd proj-$VERSION/nad
$ tar xzf ../../proj-datumgrid-$VERSION.tar.gz
$ cd ..
$ ./configure
$ make
$ sudo make install
$ sudo ldconfig
$ cd ..
# GDAL opensource geospatial library gor vector (OGR) and raster data formats
# "Geospatial Object Oriented Data Abstraction Library" (GOODAL)
# GEOS and PROJ should be installed prior to building GDAL
# GDAL commands http://download.osgeo.org/gdal/presentations/OpenSource_Weds_Andre_CUGOS.pdf
# gdal-$VERSION.tar.gz=2.1.1
$ wget http://download.osgeo.org/gdal/CURRENT/gdal-$VERSION.tar.gz
$ tar xzf gdal-$VERSION.tar.gz
$ cd gdal-$VERSION
$ ./configure
$ make
$ sudo make install
$ sudo ldconfig
$ cd ..
# The location of external shared libraries (GEOS, GDAL) has to be specified. Tipical library directory for software built from source is /usr/local/lib. By including this path in the environment variable LD_LIBRARY_PATH the configuration is set on a per-user basis.
>> export LD_LIBRARY_PATH=/usr/local/lib
# To configure it system-wide set the path in file /etc/ld.so.conf
$ sudo echo /usr/local/lib >> /etc/ld.so.conf
$ sudo ldconfig
# Libraries located in a particular location should be set in Django settings file :
>> GEOS_LIBRARY_PATH = '/home/user/local/lib/libgeos_c.so'
>> GDAL_LIBRARY_PATH = '/home/user/local/lib/libgdal.so'
# Running GeoDjango with PostGIS requires the PostgreSQL adapter psycopg2. Prior to its installation the packages below are needed (may be already on system if PostreSQL is present) :
$ sudo apt-get install python3-dev # /for compiling psycopg2 in virtualenv
$ sudo apt-get install libpq-dev
# and then the adapter for Python (activate virtualenv)
(djangodev) $ pip install psycopg2
# Other libraries might be needed :
# JSON-C - for importing GeoJSON (via the function ST_GeomFromGeoJson)
# json-c-$VERSION.tar.gz=0.12.1-20160607
$ wget https://github.com/json-c/json-c/archive/json-c-0.12.1-20160607.tar.gz
$ tar xf json-c-$VERSION.tar.gz
$ cd json-c-$VERSION
#libxml2
# libxml2-$VERSION.tar.gz=2.9.4
$ wget ftp://xmlsoft.org/libxml2/libxml2-$VERSION.tar.gz
$ tar xf libxml2-$VERSION.tar.gz
$ cd libxml2-$VERSION
# then build in folder of each extracted library
$ ./configure
$ make
$ sudo make install
$ sudo ldconfig
$ cd ..
# PostGIS - spatial component for PostgreSQL
# GEOS, PROJ.4 and GDAL should be installed prior to building PostGIS
# postgis-$VERSION.tar.gz=2.2.2
$ wget http://download.osgeo.org/postgis/source/postgis-$VERSION.tar.gz
$ tar xf postgis-$VERSION.tar.gz
$ cd postgis-$VERSION
$ ./configure
# If an error occurs it's probably missing PostgreSQL server development packages
# In that case re-run ./configure after installing server-dev
$ sudo apt-get install postgresql-server-dev-$VERSION
$ make
$ sudo make install
$ sudo ldconfig
$ cd ..
### idle themes ###
## to add custom themes edit file ~/.idlerc/config-highlight.cfg
## insert theme names and color configuration
# [Obsidian]
# https://gist.github.com/dsosby/1122904
# [desert]
# http://ubuntuforums.org/showthread.php?t=657799
# [Matrix]
# http://snipplr.com/view/53202/matrix-theme-for-idle/
# [Custom Dark]
# [Custom Light]
# http://stackoverflow.com/questions/33064424/idle-background-color-in-python
## edit file ~/.idlerc/config-main.cfg
[Theme]
default = 0
name = //your default theme name//