Force RStudio to use anaconda python 3.5 - python

I have some python scripts (python 3.5 based) which I want to call using R/RStudio. For the same, I am using rPythonpackage. Whenever I make a call to these scripts, RStudio uses python 2.7.10 as shown
import sys
print(sys.version)
2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]
but I want to use python 3.5.
On my system, python 3.5 is installed and is set to default as shown below
HaroonMacBook:~ haroonr$ python
Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I tried to force python 3.5 in RStudio by using:
Sys.setenv(PATH=paste("/Volumes/MacintoshHD2/Users/haroonr/anaconda/bin",Sys.getenv("PATH"),sep=":"))
Accordingly, I do get
> Sys.getenv("PATH")
[1] "/Volumes/MacintoshHD2/Users/haroonr/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/git/bin:/usr/texbin:/opt/local/bin"
What all are the other ways to force Rstudio for using python 3.5
UPDATE 1:
I call python code using following statements from RStudio:
library(rPython)
Sys.setenv(PATH=paste("/Volumes/MacintoshHD2/Users/haroonr/anaconda/bin",Sys.getenv("PATH"),sep=":"))
python.load("/Volumes/MacintoshHD2/Users/haroonr/Desktop/demo2.py", get.exception = TRUE)

Related

What does GCC have to do with a python interpreter?

I just noticed this on my macintosh. Running $ python fires up an interpreter session with the following lines:
$ python2.7
Python 2.7.10 (default, Feb 6 2017, 23:53:20)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
The second line of the starting up text mentions GCC and clang versions.
How are these two related to the python interpreter? Given that python is an interpreted language, there should be no whisper of a compiler at all, so I was curious as to why this is shown.
Now here's the same thing with python3.6:
$ python3.6
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
This time there's no mention of clang. Why's that?
The CPython interpreter is itself written in C. It matters what compiler was used to convert the C code into a binary executable; behaviour and performance can differ in subtle ways, so it is mentioned in the banner.
You have two different Python binaries, the differences in the banner reflect differences in how those binaries where built. Since the Python 2.7 release is the one that comes bundled with OS X, it was built by Apple engineers using a different toolchain (using the clang compiler) from the Python 3.6 installation, which you must have installed separately (OS X doesn't include Python 3.6 yet). The latter was compiled with the GCC compiler.

Python 3.x on python(x,y)?

I'm in the process of setting up a Matlab like environment so I downloaded the latest version of python(x,y) with all the modules that come with it and downloaded python 3.4.1. Does python(x,y) not run the latest version of python? I noticed because the python(x,y) shell doesn't auto calculate mathematical operations into floats which I read is a difference between python 2.x and 3.x. Do I just have to wait for a new release of (x,y) or am I missing something here?
You can make Python 2 behave the same as Python 3 w.r.t. division with the following command;
from __future__ import division
Imports from __future__ should be the in the top of the file. There is probably a way to auto-load this expression (I know it is possible in IPython) but I'm not familiar with python(x,y).
For learning more about Python do the tutorials available via python.org. The latest version of Python3 is recommend.
Since you are in a transition process, take a look at SciPy (http://www.scipy.org) and Sage (http://www.sagemath.org/tour.html). These might be a better fit for the problems you need to solve.
If you do a lot of interactive work at the terminal, take a look at ipython (http://ipython.org).
Regarding the division operator is defaults to integer division in Python2, but will be just normal division in Python3. You can change this by using the -Q flag when starting the interpreter. (Do: python --help) For example:
$ python2.7 -Qnew
Python 2.7.6 (default, Nov 18 2013, 15:12:51)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>>
$ python2.7
Python 2.7.6 (default, Nov 18 2013, 15:12:51)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>>
$ python3.4
Python 3.4.1 (default, May 21 2014, 01:39:38)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>>
Having the feeling that the original question is epsecially regarding the python(x,y)-distribution and Python 3 my (long) answer to this is:
I used this distribution for many years and like it. But for me it seems that there are no plans to upgrade it to include a python 3 environment.
These days I would recommend the Anaconda distribution/project (https://www.anaconda.com/).
Very similar to the python(x,y)-idea but better maintained and supporting the "latest of everything".

bbfreeze picks wrong python path

After upgrading to ActivePython 2.7.5.6 from ActivePython 2.7.3, bbfreeze fails with several import errors, e.g. ImportError: cannot import name MAXREPEAT. I traced the issue and it is with wrong Python version/installation picked by bbfreeze. It is weired that currently there are two system Python installations:
bash-3.2$ python
Python 2.4.3 (#1, Jun 11 2009, 14:09:37)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
and:
ash-3.2$ /usr/bin/python2.7
Python 2.7 (r27:82500, Sep 24 2010, 08:01:50)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-46)] on linux2
and a local installation:
bash-3.2$ ActivePython-2.7/bin/python
ActivePython 2.7.5.6 (ActiveState Software Inc.) based on
Python 2.7.5 (default, Sep 16 2013, 23:05:39)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2
but embeded python compler in bbfreeze give a different one, i.e. none of a bove:
bash-3.2$ bin/py
Python 2.7.1 (r271:86832, Dec 5 2010, 11:36:33)
[GCC 4.0.2 20051125 (Red Hat 4.0.2-8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(MyConsole)
I even don't know where this Python 2.7.1 is installed! Any idea how to force bbfreeze to use the local python directory. I already used virtualenv, but didn't work.
Thanks.
#AsoAgile
I downgraded ACtivePython to 2.7.3 and reinstalled bbfreeze and it worked. So bbfreeze turned out to be not supporting ActivePython 2.7.5.

Running Python 3.2 and 2.7 on the Same Machine

Is there an easy way to run both Python 2.7 and 3.2 on an OS X machine? I have been using IDLE with Python 3.2 and have numerous programs written using Python 3, so I don't really want to uninstall 3. However, I'm working on an assignment that uses 2.7 for a lot of its base code, so I'd like to be able to run 2.7.
OS X 10.7 and 10.8 come with Python 2.7 pre-installed; /usr/bin/python:
$ /usr/bin/python2.7
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Installing additional versions of python isn't prohibited however; the Python for Mac 2.7.3 installer won't interfere with the system install or your Python 3 installation.

How to install Python 3.1.2 on Mac OS X 10.6.4?

Hi there I have downloaded the mac installer here, http://www.python.org/download/releases/3.1.2/ , & installed it. But when I run terminal & type python it says:
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
What I want to know is, is it safe to run Update Shell Profile.command in the Python 3.1 folder ? or should I run python 3.1.2 separately ? If I should run python 3.1.2 separately, how do I do so ? also how do I start IDLE ?
Is there another python executable, perhaps python31?
You can also install other python versions via MacPorts if you need (although you'll still have to choose the right executable).
This should also be relevant: Multiple versions of Python on OS X Leopard

Categories

Resources