Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Saturday, June 15, 2013

Kivy

$ su
$ add-apt-repository ppa:kivy-team/kivy
$ apt-get update
$ apt-cache search kivy
$ apt-get install python-kivy
$ apt-get install python-kivy-examples

examples go into: /usr/share/kivy-examples



http://kivy.org/docs/installation/installation-ubuntu.html

http://kivy.org/docs/gettingstarted/examples.html




Tuesday, June 11, 2013

Quest for a "good" Python IDE

Continue the quest for the best Python IDE

1. WingIDE 101 (free)

Download 64 bit deb file from here

Install enscript as WingIDE needs it but is not smart enough to pull it down

$ sudo apt-get install enscript

$ sudo dpkg -i wingide-101-4.1_4.1.13-1_amd64.deb 

Conclusion. I don't like this IDE. Faster to start than pycharm but this free version is just too basic. So:

$ sudo apt-get remove wingide-101-4.1
$ sudo apt-get remove enscript

2. Ninha IDE (free)

$ sudo apt-add-repository ppa:ninja-ide-developers/ninja-ide-stable
$ sudo apt-get update
$ sudo apt-get install ninja-ide

3. Pycharm ($99)

I keep coming back to this one.

Winpdb - Python debugger

Search for winpdb:
$ sudo apt-cache search winpdb


Install winpdb:
$ sudo apt-get install winpdb

https://code.google.com/p/winpdb/wiki/DebuggingTutorial

Modify Geany "set build commands" to include a "debug" option which would execute "winpdb %f"

Python GUI

Sometimes you just want to throw together a very basic python program and you would like a decent GUI rather than a command line interface or a web page interface. Note: I am using Python 2.7.4

1. Tkinter

Tutorial, Another Tutorial

If you get "please install the python-tk package" when you try to > import Tkinter in a python shell, you need to install python-tk

$ sudo apt-get install python-tk



2. Kivy

Hmm??? Works on Android....









Python Debugger

pdb

winpdb

Friday, June 7, 2013

ipython qtconsole

To install the qtconsole:

$ sudo apt-get install ipython-qtconsole

To run:

$ ipython qtconsole



Official Doc

YouTube overview


Tuesday, May 28, 2013

stockticker (flask/mongodb) on Heroku

Creating an App

1. Create ~/.gitconfig (if not already there)

$ git config --global user.name "My Name"
$ git config --global user.email emailname@mailhost.com

2. Set-up Project Specific Development environment:

$ mkdir ~/dev/stock-fh
$ virtualenv venv
$ work stock-fh
$ git init
$ gedit .gitignore
$ gedit README.md
$ git add .
$ git commit -m "initial commit"
$ mkdir static static/css static/js static/img static/ico templates

create favicon.ico file at favicon.cc and add to static/ico

add any necessary css, js, and img files, html goes in templates dir


3. Go to bitbucket.org and create a new repo called stock.fh and then:

$ git remote add origin ssh://git@bitbucket.org/gbiglow/stock-fh.git
$ git push -u origin --all

4. install required python components and generate requirements.txt

$ pip install flask
$ pip freeze > requirements.txt
$ git add requirements.txt
$ git commit -m "added initial requirements.txt"
git push origin master

5. create a Procfile for heroku and foreman

$ echo "web: python app.py" > Procfile
$ git add Procfile
$ git commit -m "added initial Procfile"
$ git push origin master

6. Create heroku app (this also creates a heroku remote for git)

$ heroku create stock-fh
git push heroku master

7. use mongoDB on heroku




todo:
  • pip add pymongo etc. update requirements.txt
  • twitter bootstrap
  • investigate flask app generator. code. (possible automation of steps 2-6 above into a single command. hmm...

Notes:
  • This is all based on this great article.
  • The command 'work' (above) is a local script to activate a virtualenv
  • I use bitbucket rather than github as bitbucket has unlimited private repos as part of a free account.









Sunday, May 26, 2013

Using Bitbucket with Pycharm

Pycharm (the python IDE) has built in support for Github. That's nice as I want to use git for source code management. Codeschool by the way has a nice free git intro course in their electives area. Enough to get one going with git.

The free Github plan however is restrictive compared to Bitbucket's free plan.

Github: no private repos, limited to just yourself.
Bitbucket: unlimited private repos, up to 5 team members

So how does one configure Pycharm to use Bitbucket?

  1. Create a free bitbucket account
  2. Launch Pycharm and go to Settings->Plugins
  3. Click on Browse Repositories
  4. Enter Bitbucket into the search field
  5. Highlight the Bitbucket pluging and click on the "dowload & install" icon
  6. Close all windows and re-start Pycharm (required after a plug-in installation)
  7. Relauch Pycharm
  8. Return to settings and select the new Bitbucket option in the IDE section
  9. Enter Bitbucket userID and password.
  10. Click on Add SSH Key button and navigate to the SSH key you used for Bitbucket




Friday, May 17, 2013

Linux Mint Update Manager no longer runs

Update Manager asks for SU passwork but fails to run when launched from the start menu. $ sudo mintupdate results in the following: (gksudo:5105): GConf-CRITICAL **: gconf_value_free: assertion `value != NULL' failed No module named gtk No module named pygtk Traceback (most recent call last): File "/usr/lib/linuxmint/mintUpdate/mintUpdate.py", line 59, in gettext.install("mintupdate", "/usr/share/linuxmint/locale") NameError: name 'gettext' is not defined Is the resent installation of Python 2.7.4 to blame? 2.7.4 is in /usr/local/bin and is the default to current user. /usr/bin/python is the old 2.7.3 $ python Python 2.7.4 (default, May 15 2013, 21:25:05) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import gtk Traceback (most recent call last): File "", line 1, in ImportError: No module named gtk >>> import pygtk Traceback (most recent call last): File "", line 1, in ImportError: No module named pygtk >>> $ /usr/bin/python Python 2.7.3 (default, Sep 26 2012, 21:51:14) [GCC 4.7.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import gtk >>> import pygtk >>>


mucking with python (adding a newer version into /usr/local/bin) broke mintupdate as it requires a python with pygtk access. I will update this posting once that is resolved......

Tuesday, May 14, 2013

Install Pycharm on Linux Mint

Download Pycharm tarball from here

Extract it

Move it to /opt

Repair start menu if required to run bin/pycharm.sh 


Monday, May 13, 2013

install Python 2.7.5 on Linux Mint

To begin, install all the development packages required to build python. Some of these may already be on your system and you may need others beyond these. These are the ones I had to add.

$ sudo apt-get install {the packages below...}
  • build-essential
  • libreadline6-dev 
  • libncursesw5-dev
  • libncurses5-dev
  • libssl-dev 
  • libsqlite3-dev 
  • tk-dev 
  • libgdbm-dev 
  • libc6-dev 
  • libbz2-dev
  • libltdl-dev
Download Python 2.7.5 tarball from python.org
Extract it and cd into that dir.

Review the README file for hints etc.
$ pg README

Generate a make file
$ ./configure

Run generated make file to compile Python executable
$ make
NOTE: renamed /usr/local/bin/python to python2.75 so apps like minkupdate would not be broken. need to get pygtk built into /usr/local/bin/python before things are fully happy. stay tuned for resolution......



Install the new Python
$ su root
# make altinstall


Notes: 
  • If you need to restart or repeat the running of make 
    • $ make clean 
    • will delete all files from previous runs of make
  • 2.7.5 will be installed in /usr/local/bin while 2.7.3 remains in /usr/bin
  • The installation of build-essential is require as explained here. Note the other packages listed above are required to compile a fully functioning python executable. if some are missing compile will still work but functionality may be missing (like readline which is required for python shell command recall)
  • Use of altinstall explained here
  • To use this new version of python with virtual environments:
    • change to dir you want to create a vitual environment in
    • $ virtualenv -v -p /usr/local/bin/python venv
    • above command will run in verbose mode and use specified python to create a virt env called "venv".
    • If above command fails with error like can't import zlib it means you did not have all the required packages installed to your system prior to compiling and installing your new version of python.
    • Carefully read the error messages at the end of the running of Make to see you are still missing any required packages
Outstanding:
  • ensure Pycharm works as expected with 2.7.4



Python Pip & Virtualenv install on Linux Mint

this will install virtualenv and pip (but both are likely old versions):
$ sudo apt-get install python-virtualenv


use pip to upgrade itself:
$ sudo pip install pip --upgrade

use pip to upgrade virtualenv:
$ sudo pip install virtualenv --upgrade


Saturday, April 20, 2013

MongoDB Training

Great FREE MongoDB training @ https://education.10gen.com

You may need to wait until the specific course you want is scheduled but it is worth the wait.
Quality training for the right price.

A free into to MongoDB is available in the following ebook:
http://openmymind.net/2011/3/28/The-Little-MongoDB-Book/

Read about PyMongo if you want to use MongoDB with Python.



Upgrade Pycharm

To Upgrade Pycharm running on Linux Mint:

$ su
# /opt/pycharm-2.7.1/bin/pycharm.sh

follow the prompts from Pycharm to do the patch based upgrade
exit Pycharm

# chmod 755 /opt/pycharm-2.7.1/bin/pycharm.sh

Hmm looks like other executables in the bin dir may also need mode changes so non-root account can execute them.