Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vms:python:django-apache [2018/08/23 00:05]
admin [Selenium, Firefox & Geckodriver]
vms:python:django-apache [2018/08/27 23:52] (current)
admin [Using virtualenvwrapper]
Line 333: Line 333:
 We keep python 2.7 as default to make sure nothing brakes as some packages, commands and utilities are relying on it. But we'll be able to use Python 3 for our Django development. We keep python 2.7 as default to make sure nothing brakes as some packages, commands and utilities are relying on it. But we'll be able to use Python 3 for our Django development.
  
 +==== Python 3.6(.4) ====
 +
 +In case you need to use Python 3.6, here is how to compile it on Debian 9. As this is quite a power hungry process, one might consider allowing sufficient resources to the VM before executing those commands, with an i7-2720QM CPU, a 4 core / 1 GB RAM VM takes about 20 minutes to complete the compilation...
 +
 +<​Code:​bash|As root user>
 +> apt-get update && apt-get upgrade
 +> apt-get install -y make build-essential libssl-dev zlib1g-dev
 +> apt-get install -y libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm
 +> apt-get install -y libncurses5-dev ​ libncursesw5-dev xz-utils tk-dev
 +> wget https://​www.python.org/​ftp/​python/​3.6.4/​Python-3.6.4.tgz
 +> tar xvf Python-3.6.4.tgz
 +> cd Python-3.6.4
 +> ./configure --enable-optimizations
 +> make -j8
 +> make altinstall
 +</​Code>​
 +
 +To test that Python 3.6 is well installed and working, enter a Python shell:
 +
 +<​Code>​
 +> python3.6
 +Python 3.6.4 (default, Aug 27 2018, 23:04:48)
 +[GCC 6.3.0 20170516] on linux
 +Type "​help",​ "​copyright",​ "​credits"​ or "​license"​ for more information.
 +>>>​
 +</​Code>​
 +
 +The Python3.6(.4) binary will be located in ''/​usr/​local/​bin/​python3.6''​\\
 +You might want to add it to the available alternatives using the above mentioned method.
 ===== Configure the Python Virtual Environment ===== ===== Configure the Python Virtual Environment =====
 +
 +==== Using virtualenv ====
  
 We now need to create a Python virtual environment so that our Django project will be separated from the system'​s tools and any other Python projects we may be working on, we need to install the ''​virtualenv''​ command to create these environments,​ this can be done using the ''​pip''​ command. Lets' install it **for Python 3**: We now need to create a Python virtual environment so that our Django project will be separated from the system'​s tools and any other Python projects we may be working on, we need to install the ''​virtualenv''​ command to create these environments,​ this can be done using the ''​pip''​ command. Lets' install it **for Python 3**:
  
-<​Code:​bash>​+<​Code:​bash|As dev user>
 > update-alternatives --config python > update-alternatives --config python
 update-alternatives --config python update-alternatives --config python
Line 383: Line 414:
 Your prompt should change to indicate that you are now operating within a Python virtual environment,​ indicating the virtualenv name between parenthesis. Your prompt should change to indicate that you are now operating within a Python virtual environment,​ indicating the virtualenv name between parenthesis.
  
 +==== Using virtualenvwrapper ====
 +
 +''​virtualenvwrapper''​ keeps all your virtualenvs in one place, and provides convenient tools for activating and deactivating them.
 +
 +<​Code:​bash| As dev user>
 +> pip3 install virtualenvwrapper
 +> nano ~/.bashrc
 +
 +ADD
 +# LOAD VIRTUALENVWRAPPER AUTOMATICALLY
 +source virtualenvwrapper.sh
 +
 +> source ~/.bashrc
 +</​Code>​
 +
 +Let's create a ''​virtualenv''​ specifying the Python version to use:
 +
 +<​Code:​bash|As dev user>
 +> mkvirtualenv --python=python3.5 <​djangoenv>​
 +</​Code>​
 +
 +To **activate** the ''​superlist virtualenv'':​
 +<​Code:​bash|As dev user>
 +> workon <​djangoenv>​
 +(<​djangoenv>​) >
 +</​Code>​
 +
 +To **deactivate** the current ''​virtualenv'':​
 +<​Code:​bash|As dev user>
 +(<​djangoenv>​) > deactivate
 +>
 +</​Code>​
 +
 +In case you ever need to **remove** a ''​virtualenv'':​
 +<​Code:​bash|As dev user>
 +> rmvirtualenv <​djangoenv>​
 +</​Code>​
 ===== Install Django ===== ===== Install Django =====
  
Line 397: Line 465:
 Installing collected packages: pytz, django Installing collected packages: pytz, django
 Successfully installed django-2.0.6 pytz-2018.4 Successfully installed django-2.0.6 pytz-2018.4
 +</​Code>​
 +
 +=== Django version ===
 +
 +It is possible to select the version of Django you'd like to install using the ''<''​ or ''​=''​ option:
 +
 +<​Code:​bash|as dev user>
 +> cd ~/​your/​project/​path/​
 +> pip3 install "​django<​1.12"​
 </​Code>​ </​Code>​
  
Line 578: Line 655:
 ===== Selenium, Firefox & Geckodriver ===== ===== Selenium, Firefox & Geckodriver =====
  
-If you plan to use Selenium to scrape websites content, you'll need to install Firefox and Geckodriver.+If you plan to use Selenium ​for functional tests or to scrape websites content, you'll need to install Firefox and Geckodriver.
  
 Though Firefox can be launched in //​headless//​ mode using the ''​-headless''​ option, it still requires the ''​libgtk-3-0''​ and ''​xvfb''​ packages to be installed in order to run, this has been reported in Bugzilla ([[https://​bugzilla.mozilla.org/​show_bug.cgi?​id=1372998]]) but seems unlikely to ever be addressed by the Mozilla community :-( Though Firefox can be launched in //​headless//​ mode using the ''​-headless''​ option, it still requires the ''​libgtk-3-0''​ and ''​xvfb''​ packages to be installed in order to run, this has been reported in Bugzilla ([[https://​bugzilla.mozilla.org/​show_bug.cgi?​id=1372998]]) but seems unlikely to ever be addressed by the Mozilla community :-(
Line 593: Line 670:
 </​Code>​ </​Code>​
  
-You can check for the latest Geckodriver version on [[https://​github.com/​mozilla/​geckodriver/​releases|this github page]]. Note that we will install the ''​geckodriver''​ binary in our local user path, so we'll update our user's ''​.bashrc''​ file to access it under ~/​.local/​bin''​.+You can check for the latest Geckodriver version on [[https://​github.com/​mozilla/​geckodriver/​releases|this github page]]. Note that we will install the ''​geckodriver''​ binary in our local user path, so we'll update our user's ''​.bashrc''​ file to access it under ''​~/​.local/​bin'',​ because this is also where Python will install things when you use ''​pip install --user''​.
  
 <​Code:​bash|As dev user> <​Code:​bash|As dev user>