Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
75 views

Python Installation For Projects

This document provides instructions for installing and managing Python environments for projects using pyenv. It recommends installing pyenv to maintain different Python versions. It then describes how to install multiple Python versions, set a global version, create virtual environments for each project linked to a specific Python version, install packages into each virtual environment using pip, and replicate environments across machines by installing matching Python versions and requirements files.

Uploaded by

biplabdeka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Python Installation For Projects

This document provides instructions for installing and managing Python environments for projects using pyenv. It recommends installing pyenv to maintain different Python versions. It then describes how to install multiple Python versions, set a global version, create virtual environments for each project linked to a specific Python version, install packages into each virtual environment using pip, and replicate environments across machines by installing matching Python versions and requirements files.

Uploaded by

biplabdeka
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Installation for Projects

● Install pyenv to maintain different versions of python


○ tutorial and here 
○ instal pyenv-virtualenv using 
git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/
plugins/pyenv-virtualenv

○ install a few versions of python such as 


pyenv install 2.7.10
pyenv install 2.7.8
pyenv install 3.4.0 

○ set one of them as you global python


pyenv global 2.7.10 

● when creating a project


○ first create a virtualenv with the version of python that you want to use (make sure the
name of the virtual env includes the version of python)
pyenv virtualenv 2.7.10 venv_2.7.10

○ go to project directory and set it up to use this virtualenv


cd projectdir
pyenv local venv_2.7.10

○ this creates a .python-version file in your project directory. Commit it to the repository
○ install all packages that your project needs with pip install <package_name>. Then freeze
pip with
pip freeze > requirements.txt 

○ commit the requirements.txt file to the repository


● When replicating a project
○ open the .python-version file and look at the virtualenv name in it
○ create a virtualenv with the same name with the version of python thats in the name.
For example if the name is venv_3.4.0 you will first install python 3.4.0 and then use it
to create this virtualenv
pyenv install 3.4.0
pyenv virtualenv 3.4.0 venv_3.4.0

○ then install all the pip requirements


pip install -r requirements.txt

○   you should now have the intended environment. every time you cd into the project di-
rectory, pyenv automatically changes the virtualenv to venv_3.4.0  and all pip install hap-
pen there.
● Installing CV2
○ find package destination
○ make symlink to compiled cv2.so

DEPRECATED

● First we have to make sure you have a stable python version on your Mac OS X Lion
○ Use the guide here to install homebrew, python, pip, virtualenv
○ Use the guide here to install virtualenvwrapper
○ Create a virtualenv called tapp
mkvirtualenv tapp

○ Install the following in that virtual environment


pip install cv2
pip install pep8

○ Clone pyadb repo to your machine. Run the following commands inside it.
python setup.py build
sudo python setup.py install

○ Install sublime text 3.


■ Install Python PEP8 Autoformatter. Change the default indentation to 2 spaces by
adding the following to Sublime Text > Preferences > Packages Settings > Python
PEP8 Autoformat > Settings - User
{
  "indent-size": 2,
}

■ Make sure your editor is set to 2 spaces by default (View > Indentation) when you
start modifying/creating any code. Before you commit any code to the repo, make
sure you run the auto formatter via the Command Palette.
○ Replicating a virtualenv
○ Also look at
○ making virualenv play nice with git

cd ../bar
workon bar
python bar.pymkvirtualenv foo
git clone ssh://foo
cd foo
pip install -r requirements.txt
python foo.py

cd ../bar
workon bar
python bar.py

○ http://hmarr.com/2010/jan/19/making-virtualenv-play-nice-with-git/
○ running a cron job with virtualenv
0    9    *    *    *    /path/to/virtenv/bin/python /path/to/
cron_script.py

○ legacy node problems on ubuntu


○ sending emails from python via gmail
Note: a long delay between making a client connection and actually sending the mail
may lead to a closed connection
○ setting up a periodic launchd (OS X) job to run
Make your plist: ~/Library/LaunchAgents/com.dddg.tapp.[taskname].plist
launchctl load ~/Library/LaunchAgents/com.dddg.tapp.[taskname].plist
launchctl start [taskname]
launchctl list | grep [taskname]  # Make sure the status is 0
○ might need sudo to view

If this fails, you might need to put a working directory in the .plist file

You might also like