I would like to execute Python scripts using the Python/C API (I am using Mac OS X Mavericks, Xcode). Since multiple Python distributions are installed on my machine (System, Homebrew, several virtualenvs), how can I define which to use?
You can define which one to use either:
by specifying the fullpath to the executable ;
or with different aliases.
For example, I have both Python 2.7 and Python 3.2 on this machine:
$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[GCC 4.5.3] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ python3
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
[...]
$ /usr/bin/python2.7
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
[...]
$ /usr/bin/python3.2
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
[...]
Related
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)
I have installed cassandra 3.0.0 and trying to connect to connect cqlsh. when i try to hit ./bin/cqlsh from the dir of installed cassandra I am getting
python not found. I am using ubunut14.04LTS
when i type python2 in my terminal it says
python2
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
when i type python3 in my terminal it says
python3
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
so this mean it is already installed . But yes when i type
python in terminal it says
python
The program 'python' is currently not installed. You can install it by typing:
apt-get install python-minimal
even when i install python-minimal it doesn work.
please suggest..
Create a symbolic link /usr/bin/python pointing to either /usr/bin/python2 or /usr/bin/python3
I've already installed a Python via HomeBrew as you can see below:
J-MBP:runtime my$ ll `which python`
lrwxr-xr-x 1 my admin 34 Mar 31 14:20 /usr/local/bin/python -> ../Cellar/python/2.7.11/bin/python
J-MBP:runtime my$ python
Python 2.7.11 (default, Jan 22 2016, 08:29:18)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'2.7.11 (default, Jan 22 2016, 08:29:18) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]'
However, when I run jupyter notebook and double-check on the python version, it still use the old version pre-installed on the system.
import sys
sys.version
Out[3]: '2.7.10 (default, Oct 23 2015, 18:05:06) \n[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]'
I'm wondering how to change the python to the newly-installed one in Jupyter Notebook.
ipython kernel install, check current kernel path. cd to it and then vim kernel.json.
{
"display_name": "Python 2",
"language": "python",
"argv": [
"/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7",
"-m",
"ipykernel",
"-f",
"{connection_file}"
]
}
Change argv argument to the newly-installed python path will solve the problem.
you can type which jupiter and edit the file. I guess that the previous version that was installed from homebrew is hardcoded in that file's shebang line to the path that which python returns
i update python from 2.7.3 to 2.7.9 in raspberry ..
first i download source from python.org and configure & make & make install
no when i command python in terminal python 2.7.9 executed ...
Python 2.7.9 (default, Jan 27 2015, 21:20:44)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
but all module that i installed from apt-get install is now unknown ...
like sudo apt-get install python-bluez
how can i fix it ?
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.