Project

General

Profile

Support #876

Updated by Daniel Curtis about 6 years ago

This is a guide for setting up a simple development environment for Python 2.7 with virtualenv on Arch Linux. 

 h2. Prepare the Environment 

 * Make sure the system is up to date: 
 <pre> 
 pacman -Syyuu 
 </pre> 

 h2. Install Python 

 * Install python and a few dependencies: 
 <pre> 
 pacman -S python2 python2-{pip,pkgconfig,setuptools,virtualenv} python python2-{pip,pkgconfig,setuptools27,virtualenv} 
 </pre> 

 * Create a non-privileged user to develop with: 
 <pre> 
 useradd -m -g users -s /bin/bash -c "Python Dev" pydev 
 passwd pydev 
 </pre> 

 h3. Use Python2 Explicitly 

 * Switch to the python dev user: 
 <pre> 
 su - pydev 
 </pre> 

 * First create a bin folder in the pydev user home directory: 
 <pre> 
 mkdir ~/bin 
 </pre> 

 * Then add a symlink python to python2 and the config scripts in it: 
 <pre> 
 ln -s /usr/bin/python2 ~/bin/python 
 ln -s /usr/bin/python2-config ~/bin/python-config 
 </pre> 

 * Finally put the new folder at the beginning of your PATH variable: 
 <pre> 
 echo 'export PATH=~/bin:$PATH' >> ~/.bash_profile 
 </pre> 

 * Exit from the pydev user session: 
 <pre> 
 exit 
 </pre> 

 h2. Create Virtualenv 

 * Switch to the python dev user: 
 <pre> 
 su - pydev 
 </pre> 

 * Create a new virtualenv called new_app: 
 <pre> 
 virtualenv2 new_app 
 </pre> 

 * Activate the new_app virtualenv to begin using it: 
 <pre> 
 source ./new_app/bin/activate 
 </pre> 

 * Install or develop the new_app: 
 <pre> 
 pip install new_app 
 </pre> 

 * When done working in the virtual environment for the moment, deactivate it: 
 <pre> 
 deactivate 
 </pre> 

 h2. wxPython in virtualenv 

 * Switch to the python dev user: 
 <pre> 
 su - pydev 
 </pre> 

 * Activate the new_app virtualenv to begin using it: 
 <pre> 
 source ./new_app/bin/activate 
 </pre> 

 * Install wxpython: 
 <pre> 
 pip install wx 
 </pre> 

 * Deactivate and reactivate new_app virtualenv to refresh libraries: 
 <pre> 
 deactivate 
 source ./new_app/bin/activate 
 </pre> 

 h3. Test wxPython in virtualenv 

 * Start an iPython session: 
 <pre> 
 ipython 
 </pre> 
 #* And use the following code example to test windows 
 <pre> 
 import wx 
 app = wx.App(False) 
 frame = wx.Frame(None, wx.ID_ANY, "Running from virtualenv!") 
 frame.Show(True) 
 app.MainLoop() 
 </pre> 

 h2. Resources 

 * https://wiki.archlinux.org/index.php/python 
 * http://docs.python-guide.org/en/latest/dev/virtualenvs/ 
 * http://stackoverflow.com/questions/14141431/cant-use-wxpython-in-virtualenv

Back