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
Last revision Both sides next revision
vms:python:dev [2017/03/31 19:10]
admin [Python Versions]
vms:python:dev [2017/05/31 02:54]
admin [Virtualenvwrapper]
Line 43: Line 43:
  
 <​Code>​ <​Code>​
-python -V+python -V
 Python 2.7.9 Python 2.7.9
 > pip -V > pip -V
Line 59: Line 59:
 Notice that ''​python''​ and ''​python2''​ are the same, this is also true for ''​pip''​ and ''​pip2''​. Notice that ''​python''​ and ''​python2''​ are the same, this is also true for ''​pip''​ and ''​pip2''​.
 ===== Virtual Environments ===== ===== Virtual Environments =====
 +[[http://​joebergantine.com/​blog/​2015/​apr/​30/​installing-python-2-and-python-3-alongside-each-ot/​]]
  
-Virtual Environments are used to isolate ​project ​python versions and package dependencies.+Virtual Environments are used to isolate python versions and package dependencies ​for each specific project.
  
-As stated before, we'lll install ''​virtualenv''​ for User only in order to allow coexistence of Python2 and Python3:+We'll begin by creating specific users for python: 
 +<​Code:​bash>​ 
 +> adduser py2 
 +... 
 +<​password>​ 
 +... 
 +> adduser py3 
 +... 
 +<​password>​ 
 +... 
 + 
 +# To act as py2: 
 +> su py2  
 +</​Code>​ 
 + 
 +We'​ll ​install ''​virtualenv''​ for User only in order to allow coexistence of Python2 and Python3. As the virtualenv binary will bear the same name for 2 & 3, we'll move them on the go: 
 + 
 +=== Virtualenv 2 ===
  
 <​Code>​ <​Code>​
 > pip install --user virtualenv > pip install --user virtualenv
 +> mv ~/​.local/​bin ~/​.local/​lib/​python2.7/​
 > nano ~/.bashrc > nano ~/.bashrc
 ADD: ADD:
-alias virtualenv2='~/​.local/​bin/​virtualenv'​+# USER INSTALLED BINARIES [virtualenv(wrapper)] 
 +export PATH=$PATH:~/​.local/​bin/​
  
-> source .bashrc +> source ​~/.bashrc 
-virtualenv2 ​--version+virtualenv ​--version
 15.1.0 15.1.0
 </​Code> ​ </​Code> ​
Line 80: Line 100:
 > source env_name/​bin/​activate > source env_name/​bin/​activate
 > cd env_name > cd env_name
 +[> deactivate]
 </​Code>​ </​Code>​
  
Line 87: Line 108:
 > virtualenv2 . > virtualenv2 .
 > source ./​bin/​activate > source ./​bin/​activate
 +[> deactivate]
 </​Code>​ </​Code>​
  
 +=== Virtualenv 3 ===
 +
 +Please note that in the case of ''​virtualenv 15.1.0'',​ the version seems to be compatible with both Python2 and Python3, so it might not be necessary to duplicate the operation, but we'll go for it anyways. ​
 +
 +<​Code>​
 +> pip3 install --user virtualenv
 +> mv ~/​.local/​bin ~/​.local/​lib/​python3.4/​
 +> nano ~/.bashrc
 +ADD:
 +alias virtualenv3='​~/​.local/​lib/​python3.4/​bin/​virtualenv'​
 +
 +> source ~/.bashrc
 +> virtualenv3 --version
 +15.1.0
 +</​Code> ​
 +
 +==== Virtualenvwrapper ====
 +
 +[[https://​virtualenvwrapper.readthedocs.io/​en/​latest/​]]
 +
 +=== Installation & Configuration ===
 +
 +Install virtualenvwrapper for python3 for the user only:
 +<​Code>​
 +> pip3 install --user virtualenvwrapper
 +> mv ~/​.local/​bin/​* ~/​.local/​lib/​python3.4/​bin/​
 +> rm ~/​.local/​bin
 +> mkdir -p projects/​code
 +> nano .bashrc
 +ADD:
 +
 +# USER INSTALLED BINARIES [virtualenv(wrapper)]
 +export PATH=~/​.local/​bin:​$PATH
 +
 +# VIRTUALENVWRAPPER
 +export WORKON_HOME=$HOME/​.virtualenvs
 +export PROJECT_HOME=$HOME
 +export VIRTUALENVWRAPPER_PYTHON=/​usr/​bin/​python[2|3]
 +export VIRTUALENVWRAPPER_VIRTUALENV=$HOME/​.local/​bin/​virtualenv
 +
 +source $HOME/​.local/​bin/​virtualenvwrapper.sh
 +
 +> source .bashrc
 +virtualenvwrapper.user_scripts creating /​home/​dev/​.virtualenvs/​premkproject
 +...
 +...
 +virtualenvwrapper.user_scripts creating /​home/​dev/​.virtualenvs/​get_env_details
 +
 +> mkvirtualenv temp
 +Using base prefix '/​usr'​
 +New python executable in /​home/​dev/​.virtualenvs/​temp/​bin/​python3
 +Also creating executable in /​home/​dev/​.virtualenvs/​temp/​bin/​python
 +Installing setuptools, pip, wheel...done.
 +...
 +...
 +(temp) >
 +</​Code>​
 +
 +=== Projects management ===
 +
 +[[http://​wiki.strategicz.com/​vhyper/​doku.php?​id=vms:​python:​django#​using_a_shared_folder_to_host_your_projects]]
 +<​Code>​
 +> VBoxManage setextradata <​VM_NAME>​ VBoxInternal2/​SharedFoldersEnableSymlinksCreate/<​SHARE_NAME>​ 1
 +</​Code>​
 +
 +<​Code>​
 +> nano /etc/fstab
 +
 +# automount shuup project space
 +<​SHARE_NAME> ​  /​home/​dev3/​projects ​  ​vboxsf ​  ​defaults,​uid=1001,​gid=1001,​dmode=775,​fmode=774,​umask=002 ​ 0   0
 +
 +</​Code>​
 +
 +[[https://​virtualenvwrapper.readthedocs.io/​en/​latest/​projects.html#​project-management]]
 +
 +===== Django =====
  
 +[[http://​wiki.strategicz.com/​vhyper/​doku.php?​id=vms:​python:​django]]