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".
Related
I'm trying to run the benchmarks game repo bencher script which was written in python 2 and requires the gtop module, NOT the pygtop module. After searching everywhere and even following their README.md I could not figure out how to get this in my python 2.7.18 virtual environment (created and maintained using pyenv).
I decided to have a look at my system version of python 2.7.18 as I followed the guide from this SO reply and the packages downloaded/installed successfully. My system version of python can import the module just fine:
Python 2.7.18 (default, Mar 8 2021, 13:02:45)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtop
>>> gtop.__file__
'/usr/lib/python2.7/dist-packages/gtk-2.0/gtop.so'
So apparently it comes as a .so which I've researched is like a DLL library for Ubuntu (correct me if I'm wrong)?
Is there a way for me to just copy this into my virtual environment of the same python version?
Thank you to #SamBob for suggesting the SO reply that led to the answer.
What I've been mistakenly doing is copying the gtk-2.0 directory into my virtualenvs site-packages such that:
$HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtk-2.0/gtop.so
What I've done is instead copy just the gtop.so library into the virtualenvs site-packages, and it seemed to recognise it no problem, such that
$HOME/.pyenv/versions/<venv>/lib/python2.7/site-packages/gtop.so
Here is my output now:
Python 2.7.18 (default, Oct 18 2021, 23:18:58)
[GCC 9.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gtop
>>> gtop.__file__
'/home/muffin/.pyenv/versions/project-2.7.18/lib/python2.7/site-packages/gtop.so'
>>>
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.
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)
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.
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