The documentation of the Python readline module says "Availability: Unix". However, it doesn't appear to be available on OS X, although other modules marked as Unix are available. Here is what I'm using:
$ uname -a
Darwin greg.local 8.11.1 Darwin Kernel Version 8.11.1: Wed Oct 10 18:23:28 PDT 2007; root:xnu-792.25.20~1/RELEASE_I386 i386 i386
$ which python
/usr/bin/python
$ python
Python 2.3.5 (#1, Nov 26 2007, 09:16:55)
[GCC 4.0.1 (Apple Computer, Inc. build 5363) (+4864187)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline
Traceback (most recent call last):
File "", line 1, in ?
ImportError: No module named readline
>>>
I have also installed Python 2.5 through MacPorts but readline is not available there either.
What can I do to provide readline functionality for Python's raw_input() function on OS X?
Have you tried to install the py-readline (or py25-readline for Python 2.5) port?
Also, in the snippet above, you are NOT using the MacPort python, but rather the Apple Python.
The MacPort version should be located in the /opt/local directory structure. You should check your path.
Try rlwrap. It should work with any version of python and in general any shell.
Install via brew install rlwrap on Mac OS X
usage as rlwrap python. It stores history as well.
It's not shipped in OS X because of licensing issues (restrictions brought to you by the GPL).
Macports python should be fine if you have the readline package installed.
You should be able to get readline support on Mac's native Python. Apparently it's implemented via BSD's editline, and you have to start it up slightly differently. I just tested this on a Mac, and it works fine (OS X 10.5.7). See man python for more details, the section "Interactive Input Editing and History Substitution" - mirrored on the web here.
luga ~ $ python
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import rlcompleter
>>> import readline
>>>
Related
There's something wrong with my OSX system and python that no amount of googling has fixed. I've uninstalled all traces of python except the system python package with OSX that I'm not supposed to uninstall, and then started afresh with a new python from python.org, and installed pip.
Now...not sure if this particular behavior below is part of the issue, but it seems strange to me:
I ran python twice. Once with sudo and once without. Without sudo, I can't access pip. What's going on?
$ sudo /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pip
However...
$ /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pip
>>>
I've already referred to: sudo python runs old python version
I have nothing in my .bash_profile, or anything in any other profiles.
All I've done is the following:
export PYTHONPATH=/lib/python2.7/site-packages/
ls $PYTHONPATH returns:
_markerlib pip pkg_resources.pyc setuptools-8.0.1.dist-info virtualenv.pyc
easy_install.py pip-1.5.6.dist-info setuptools virtualenv-1.11.6.dist-info virtualenv_support
easy_install.pyc pkg_resources.py setuptools-7.0.dist-info virtualenv.py
which pip returns:
/bin/pip
sudo overrides your export. It's the same Python (as you can easily tell from the version information it prints) but it runs with a different (system default) PYTHONPATH.
This is one of the jobs of sudo; it sanitizes the environment to safe defaults. You may be able to tweak this, but the real question is, what are you trying to accomplish? If you need to run as root with a particular environment, set up a virtualenv and/or write a wrapper script which sets things up before dispatching Python.
What do you get when you compare the output of which pip and sudo which pip?
On my system I get different outputs. If you do, I'm not sure how to fix that, but you could try to force the sudo'd python to look in the correct directory:
import sys
sys.path.insert(0, '/lib/python2.7/site-packages/')
import pip
Working inside a virtualenv, I'm trying to install scikit-image, but it fails, telling me that I need a newer (or any) version of numpy.
$ sudo pip install -U scikit-image
...
ImportError: You need `numpy` version 1.6 or later.
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /Users/aps/Dropbox/experiments/build/scikit-image
I don't understand this, because from Python, numpy 1.7 is already on my path.
$ python
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[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.
>>> import numpy
>>> numpy.__version__
'1.7.1'
What is going on - why can't the system installing scikit-image see the newest version of numpy? And how can I fix this?
The path to numpy already seems to be in my ~/.bash_profile:
>>> numpy.__path__
['/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy']
>>> exit()
$ vi ~/.bash_profile
...
export PYTHONPATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:$PYTHONPATH
UPDATE:
numpy version 1.7 is also in the su path:
$ sudo python
Password:
Python 2.7.5 (default, Aug 1 2013, 00:59:40)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.7.1'
You need to make sure that all those packages are available within the virtualenv itself. Did you try running pip freeze after sourcing bin/activate? Using the virtualenv package, the only library that comes "preinstalled" by default is distribute, and all other dependencies must be manually added. With venv (built into py3k) all of your system libraries should be available directly. Which are you using?
I am installing modules with homebrew and other installers, and they are not recognized by my default python. Module installations with easy_install (such as pip) appear to be available for my system and system python).
My default python is located here and is this version:
15:49 [~]: which python
/usr/local/bin/python
15:49 [~]: python -d
Python 2.7.2 (default, Mar 18 2012, 15:13:08)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin Type "help",
"copyright", "credits" or "license" for more information.
The packages do appear to be located in /library/frameworks/, GEOS.framework is one example.
What do I need to modify to gain access to my modules?
System: Mac os x 10.5.8
From the Homebrew page: "Homebrew installs packages into their own isolated prefix and then symlinks everything into /usr/local"
I think that the OS X preinstalled python looks for modules in
/Library/Frameworks/Python.framework/Versions/Current//lib/python2.7/site-packages
So maybe you need to symlink your Homebrew installed packages to there.
I use Webfaction, and this is the command line for the shared host.
[zallarak#web198 ~]$ python2.6
Python 2.6.5 (r265:79063, Nov 23 2010, 02:02:03)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import stripe
>>>
[zallarak#web198 ~]$ python2.7
Python 2.7.1 (r271:86832, Dec 1 2010, 06:29:57)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-48)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import stripe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named stripe
I know there must be a simple way to make it work in all version of Python. I would much appreciate any insight on how to make this work/the concept behind it.
My version of Django runs on 2.7, so the goal is to make it work on 2.7
Your problem is that the stripe module is not installed in each python environment.
I know there must be a simple way to make it work in all version of Python.
You must install stripe in each environment. According to your webhost, you should be able to install them with easy_install. Try this:
python2.7 `which easy_install` stripe
Brian Cain is correct about it not being installed in the Python version you are using. Instead of the command he gave you should run:
easy_install-2.7 stripe
After making sure that the directory: /home/username/lib/python2.7/ actually exists. If it doesn't you can use the command: mkdir -p /home/username/lib/python2.7 to create it.
That will install it in your Python2.7 installation, which you can then use from Django on Python2.7.
Note: If you get the error: "Need libcurl version 7.19.0 or greater to compile pycurl." you'll need to follow the instructions here:
http://community.webfaction.com/questions/6365/problems-installing-pycurl
to install your own version of curl on your account.
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