Tuesday, September 3, 2013

Installing VPython (Visual Python) on Linux

VPython on Linux is a pain to install because they recommend using WINE or compiling from source.  I was able to compile from source but it took over an hour to compile a special patched version of wxPython and then compile that into VPython.  It was a less than "fun" experience and requires knowledge of compiling.  I discovered this during Kirby Urner's Leveraging Python tutorial at DjangoCon US 2013. So I set out to find a better way with fellow attendee German Larrain.

We're waiting on a pull request to the main GitHub repo that fixes our problems however we figured out a way to install VPython using PIP.  Its as easy as using PIP ability to install from a GIT repo.  In the meantime, you can use German's fork of VPython at GitHub:

sudo pip install git+git://github.com/glarrain/vpython-wx.git

Edit (Nov. 2013):

The pull request mentioned above has been merged into the main VPython git repo.  However the installation instructions have changed due to the addition of the Numpy package and on my system I needed to install a newer WxPython (which much have been installed on my old system and why it wasn't on the original instructions).

Here's how I installed WxPython 2.9.4 on Ubuntu 13.10 (saucy -- no deb was available yet).  I couldn't get 2.9.5 to build on my system - it kept failing in the make process at random places. You do need GTK2 dev package (as indicated as the first command) if you do not have that installed yet and the gstreamer base dev package (second command).  If you get errors about missing .h files, then your system is missing a -dev version of some package that is indicated.
sudo apt-get install g++ libgtk2.0-dev freeglut3-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev python-dev libgtkglextmm-x11-1.2-dev libboost-python-dev libboost-signals-dev libboost-python-dev libboost-thread-dev tk
wget http://downloads.sourceforge.net/project/wxpython/wxPython/2.9.4.0/wxPython-src-2.9.4.0.tar.bz2
tar -xvf wxPython-src-2.9.4.0.tar.bz2
cd wxPython-src-2.9.4.0/wxPython
python build-wxpython.py --build_dir=../bld

Note the output that say something like -- we will need this later:
To run the wxPython demo you may need to:
 - set your PYTHONPATH variable to /home/peter/wxPython-src-2.9.4.0/wxPython
 - set your LD_LIBRARY_PATH to /home/peter/wxPython-src-2.9.4.0/bld/lib

Note that Numpy will take some time compiling all the C code on your system. I have an i7 with 8 cores it took a few minutes -- may look like it hangs, but be patient. Also, it may take some time for PIP to download the tarball depending on your internet connection speed -- it may look like it hangs downloading, but again be patient.
sudo pip install numpy
sudo pip install https://github.com/BruceSherwood/vpython-wx/archive/master.zip

At this point, we need to create .sh executable to run vidle.  Create a file named vidle.sh with the following text (replace paths with the stuff we noted above) and ensure this file is executable (chmod 777 vidle.sh).
export PYTHONPATH="/home/peter/wxPython-src-2.9.4.0/wxPython"
export LD_LIBRARY_PATH="/home/peter/wxPython-src-2.9.4.0/bld/lib"
python /usr/local/lib/python2.7/dist-packages/VPython-6.03-py2.7-linux-x86_64.egg/vidle/idle.py

9 comments:

  1. Thanks for the reference Peter. Let's hope we can solve this. It would be a pity to lose potential users just because of installation problems!

    ReplyDelete
  2. Cool stuff.Thanks for your share.BTW,is there any way to install it in the Windows? Thanks.

    ReplyDelete
  3. Yeah, there is an exe install on VPython.org

    ReplyDelete
  4. HI, Peter,

    Thank you for your efforts. I love Visual Python and I'm a fan of Kirby's stuff, too. I've been trying to install VP on my Ubuntu laptop for a few weeks now and it's not looking good. I admit I'm a Linux newbie and if making mistakes is progress, then I'm making terrific progress. Did the pip install, now what?

    PS If this works, I swear I'll make a video of this procedure for other lost souls.

    ReplyDelete
  5. Did the pip install work for you? Or were there errors listed?

    ReplyDelete
  6. It took a long time and it did generate a lot of output, some of which may have been errors. But there was still "no module named visual" so I'll try your new instructions and let you know how that goes.

    Do I have to undo anything before trying them? I already have numpy working, for example.

    ReplyDelete
  7. Have you tried to run Vidle.sh as I mentioned to open up an interactive console?

    ReplyDelete
  8. Hi, Peter,

    Last night I did everything as you directed, and the install took forever! The next morning it was done, I made the .sh file, ran it from the desktop and got this error message:

    peter@peter-Satellite-C55D-A:~/Desktop$ ./vidle.sh
    python: can't open file '/usr/local/lib/python2.7/dist-packages/VPython-6.03-py2.7-linux-x86_64.egg/vidle/idle.py': [Errno 2] No such file or directory
    ./vidle.sh: line 7: -: command not found

    ReplyDelete
  9. @Peter A Farrell: In this case, the path /usr/local/lib/python2.7/dist-packages/VPython-6.03-py2.7-linux-x86_64.egg/vidle/idle.py is probably different on your system. Just look in your file explorer and find the right path and replace it in your vidle.sh file you created.

    ReplyDelete