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.
Related
I have followed all the possible suggestion on stack overflow with no success.
When I run python --version the result :
Home-Macbook-Pro:~ pcmac$ python
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Jun 5 2020, 22:59:21)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit ()
How can I uninstall or force terminal to use Python version 3.8 please
Also the IDLE is running on old Python version 2.7.16
I had the same issue and this solution worked for me:
I am using macOS Catalina version 10.15.6 and used homebrew to install python 3.8.5.
All I did was type 'nano .zprofile' in terminal and then typing: alias python='python3' and saving it by hitting Ctrl+o and then Enter.
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 am writing a simple Python script that fetches data from a sqlite3 database. I am experiencing the following error:
sqlite3.DatabaseError: file is encrypted or is not a database
I found out that this error is caused by a version problem of sqlite3. On the Mac (10.6.8) I need to use for now the SQLite version is 3.6.12. I downloaded SQLite 3.7.16.2 and can open the database with that version. But how can I tell Python to use the non-standard SQLite version in that script?
I am using
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Eventually I will use Ubuntu for that project but for testing purposes I need to run the script on that particular Mac configuration.
Thanks for helping!
Another option is to install a newer Python. For instance, the current python.org Python 2.7.4 installers (available here) ship with SQLite 3.7.13.
$ /usr/local/bin/python2.7
Python 2.7.4 (v2.7.4:026ee0057e2d, Apr 6 2013, 11:43:10)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
>>> sqlite3.sqlite_version_info (3, 7, 13)
You can use DYLD_LIBRARY_PATH environment variable to place the directory of a replacement sqlite .dyld earlier in the search path. See man dyld. This is similar to LD_LIBRARY_PATH on Linux.
I've installed Python via MacPorts. According to this question, the files in /opt/local/bin should run the "correct" Python version. However, all those files are symlinks to:
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/bin/
Running them directly from that folder (using no symlinks) runs an Apple build of Python!
Python 2.6.6 (r266:84292, Jan 6 2011, 13:25:25)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
For comparison, running /usr/bin/python shows a slightly different version:
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
They're both Apple builds! How do I install the correct version?
There are no "Apple builds" except the system Python (which is 2.6.1 on Snow Leopard, afai can deduce). The ports install seems to have worked as expected in this case. The reference to Apple is a reference to which GCC that was used.
I think it is running the build you want.
macports install every thing in /opt/local. So /opt/local/bin/python is a macport distribution.
/usr/bin/python is pre-install python distribution that comes with mac os x.
The following line, is an information about gcc build which is used for building macport python distribution.
[GCC 4.2.1 (Apple Inc. build 5664)]
If you have multiple versions of macport python installed, you can select the version using python-select
sudo port install python-select sudo
python-select python26
Also to ensure that you use macport python you could add the following to the PATH
export PATH=/opt/local/bin:$PATH
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