Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Script to run in Python 3

I have a script that I wrote in Python 3, and while experimenting with GUIs, I found one I seemed to like called Kivy. Everyone is saying it works with Python 3, but whenever I run it, it runs in Python 2.7. How can I either

A: Get Kivy to run in Python 3 completely

or

B: Force the script that part of my Kivy app calls to run in Python 3.

I'm on OS X 10.10 with both python 3 and 2 installed.

I just tried

myModule.py:

#!/usr/bin/env python3

import sys
def getVersion():
    return sys.version_info

Where I run kivy myapp.py that all it does it print a label with getVersion() as the content of that label. But that still seems to show 2.7.

like image 616
cclloyd Avatar asked Mar 30 '15 18:03

cclloyd


2 Answers

She-bang the Python version that you want your GUI to run, using something like

#!/usr/bin/env python3

at the top of the .py file. Alternatively, you can set up your virtualenv to run Python 3 with the command-line argument:

virtualenv -p /usr/bin/python3.4
like image 76
miradulo Avatar answered Oct 05 '22 23:10

miradulo


The package for OSX is built for Python 2.7 - it will not run with Python 3.x. While the code is compatible with either Python version, the compiled parts must be compiled for one or the other and not both.

You may be able to use Python 3.3 by modifying the kivy.sh script and changing the command from python2.7 to python3.3, then entering the kivy folder inside the package and running make force. This would rebuild for Python 3, assuming you have Cython installed for Python 3 (preferably version 0.21.2, do not use 0.22 as it will not work). I don't have an OSX machine to check this on though, so YMMV.

Best choice is probably to wait, as we should have a 1.9.0 release available soon and that should include a Python 3 package.

like image 44
kitti Avatar answered Oct 05 '22 22:10

kitti