Django/Python on FreeBSD: First Steps

2019-08-25 13:53:52+00

I'm starting a new web project and taking the opportunity to evaluate Django/Python on FreeBSD.

First, let's see if python is already installed

$ pkg info | grep python
python27-2.7.16_1              Interpreted object-oriented programming language
python36-3.6.8_2               Interpreted object-oriented programming language
 # python3.6
Python 3.6.8 (default, May 11 2019, 08:32:34) 
[GCC 4.2.1 Compatible FreeBSD Clang 6.0.1 (tags/RELEASE_601/final 335540)] on freebsd12
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

Installation of the package manager

# cd /usr/ports/devel/py-pip/ && make install clean
py36-virtualenv-16.0.0_1 depends on file: /usr/local/sbin/pkg - found

Install virtualenv on FreeBSD

# cd /usr/ports/devel/py-virtualenv/ && make install clean
===>  Building for py36-virtualenv-16.0.0_1
running build
running build_py
creating build
creating build/lib
copying virtualenv.py -> build/lib
creating build/lib/virtualenv_support
copying virtualenv_support/__init__.py -> build/lib/virtualenv_support
copying virtualenv_support/pip-10.0.1-py2.py3-none-any.whl -> build/lib/virtualenv_support
copying virtualenv_support/setuptools-39.1.0-py2.py3-none-any.whl -> build/lib/virtualenv_support
copying virtualenv_support/wheel-0.31.1-py2.py3-none-any.whl -> build/lib/virtualenv_support
===>  Staging for py36-virtualenv-16.0.0_1
===>   py36-virtualenv-16.0.0_1 depends on package: py36-setuptools>0 - found
===>   py36-virtualenv-16.0.0_1 depends on file: /usr/local/bin/python3.6 - found
===>   Generating temporary packing list
# pip-3.6

Usage:   
  pip  [options]

Commands:
  install                     Install packages.
  download                    Download packages.
# pip install Django
Collecting Django
  Downloading https://files.pythonhosted.org/packages/eb/4b/743d5008fc7432c714d753e1fc7ee56c6a776dc566cc6cfb4136d46cdcbb/Django-2.2.2-py3-none-any.whl (7.4MB)
    100% |################################| 7.5MB 161kB/s 
Collecting pytz (from Django)
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
    100% |################################| 512kB 2.2MB/s 
Collecting sqlparse (from Django)
  Downloading https://files.pythonhosted.org/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
Installing collected packages: pytz, sqlparse, Django
Successfully installed Django-2.2.2 pytz-2019.1 sqlparse-0.3.0
# python3.6
Python 3.6.8 (default, May 11 2019, 08:32:34) 
[GCC 4.2.1 Compatible FreeBSD Clang 6.0.1 (tags/RELEASE_601/final 335540)] on freebsd12
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
2.2.2
>>> exit()
# pip install psycopg2
Collecting psycopg2
  Downloading https://files.pythonhosted.org/packages/5c/1c/6997288da181277a0c29bc39a5f9143ff20b8c99f2a7d059cfb55163e165/psycopg2-2.8.3.tar.gz (377kB)
     |################################| 378kB 10.7MB/s 
Installing collected packages: psycopg2
  Running setup.py install for psycopg2 ... done
Successfully installed psycopg2-2.8.3
# python3.6 -m django --version
2.2.2
# django-admin startproject vp4proj
# ls -altr vp4proj;
total 16
-rwxr-xr-x  1 root  wheel  625 Jun 30 10:05 manage.py
drwxr-xr-x  3 root  wheel  512 Jun 30 10:05 .
drwxr-xr-x  2 root  wheel  512 Jun 30 10:05 vp4proj
drwxr-xr-x  8 root  wheel  512 Jun 30 10:05 ..
#cd vp4proj; 
# python3.6 manage.py startapp vpapp
# ls -altr
total 20
-rwxr-xr-x  1 root  wheel  627 Jun 30 11:16 manage.py
drwxr-xr-x  3 root  wheel  512 Jun 30 11:16 ..
drwxr-xr-x  3 root  wheel  512 Jun 30 11:17 vp4proj
drwxr-xr-x  3 root  wheel  512 Jun 30 11:31 vpapp
drwxr-xr-x  4 root  wheel  512 Jun 30 11:31 .


# cd /usr/ports/www/uwsgi/ && make install clean
     This port has installed the following startup scripts which may cause
      these network services to be started at boot time.
/usr/local/etc/rc.d/uwsgi
# pip install uwsgi
Collecting uwsgi
  Downloading https://files.pythonhosted.org/packages/e7/1e/3dcca007f974fe4eb369bf1b8629d5e342bb3055e2001b2e5340aaefae7a/uwsgi-2.0.18.tar.gz (801kB)
     |################################| 808kB 10.9MB/s 
Installing collected packages: uwsgi
  Running setup.py install for uwsgi ... done
Successfully installed uwsgi-2.0.18

Install virtualenv

# virtualenv uwsgi-wnk
Using base prefix '/usr/local'
New python executable in /usr/ports/devel/py-virtualenv/uwsgi-wnk/bin/python3.6
Also creating executable in /usr/ports/devel/py-virtualenv/uwsgi-wnk/bin/python
Installing setuptools, pip, wheel...done.

Tag: django2