Python interactive mode history and arrow keys - python

I was wondering if anyone can explain why all of a sudden in Python interactive mode all arrow keys are failing?
When I press up button for example to go through command history I get "^[[A". Same with any other arrow keys.
I have no idea why this happened and it was working before (on OS X Snow Leopard). Does anyone know a way to fix this?
Many thanks,
G

If you are using homebrew, this is an easy fix:
brew uninstall python
brew uninstall readline
brew install readline --universal
brew install python
That fixed it for me (running OS X Mavericks 10.9.5)

I finally got this working. I just had to install readline with easy_install and cursors and backspace started magically working.
sudo /opt/local/bin/easy_install-2.5 readline

You don't say which Python you are using but the symptoms you mention are indeed usually caused by Python not being built with readline support. These days Python on OS X can be built to use either the GNU readline library or the Apple-supplied editline library (AKA libedit). You can use the following two commands to show exactly which Python you are using. If that does not help you figure out what is going on, edit your question to show the output from those commands.
Here's an example that shows a recent MacPorts Python 2.6 on OS X 10.6:
$ python -c 'import sys;print(sys.version);print(sys.executable)'
2.6.5 (r265:79063, Jul 15 2010, 01:53:46)
[GCC 4.2.1 (Apple Inc. build 5659)]
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python
$ otool -L $(python -c 'import readline; print(readline.__file__)')
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/readline.so:
/opt/local/lib/libreadline.6.1.dylib (compatibility version 6.0.0, current version 6.1.0)
/opt/local/lib/libncursesw.5.dylib (compatibility version 5.0.0, current version 5.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)
The path prefix /opt/local/ is the default location for MacPorts-installed software and the output from otool indicates that this Python's readline module is dynamically linked to the MacPorts-installed GNU readline library.

This behaviour commonly shows when you do not have readline support. If you are using MacPorts, try port install readline, see if it will fix it. You can also see this page for some further explanations.
(Also useful to know: some programs do not use readline even if present on the system. You can force it on them by using rlwrap (port install rlwrap). For example: rlwrap ocaml -init code.ml will start up OCaml, read code.ml, and start REPL with readline support)

The command
brew install readline
worked for me.

Related

Python python_keyring package - Upgrade of Python has broken keyring

I have upgrade from python 3.9.6 to 3.10.5 and kept thankfully the old version. This is on a Win-64 machine so should be using the WinVault backend (default)
I have copied all the site_packages from 3.9.6 to 3.10.5 (except for those already installed by the newer version)
Running keyring under 3.10.05 the error is
keyring.errors.NoKeyringError: No recommended backend was available. Install a recommended 3rd party backend package; or, install the keyrings.alt package if you want to use the non-recommended backends. See https://pypi.org/project/keyring for details.
I can run the same code under 3.9.6 with no problems.
Running
python -c "import keyring.util.platform_; print(keyring.util.platform_.config_root())"
or
python -c "import keyring.util.platform_; print(keyring.util.platform_.data_root())"
under either version is producing locations that don't really exist. I have created a keyringrc.cfg file with a keyring.backends.Windows.WinVaultKeyring line but it doesn't seem to do anything
I don't mind having to re-enter keyring passwords but would like to get this working under 3.10.5.
Ideas
This has eventually turned out to be needs to upgrade cffi which has fixed the problem.

I can't open IDLE3 on osx11.1

I've installed python 3.9.1 by homebrew.
benlai#laihongbindeAir ~ % idle3
macOS 11 or later required !
zsh: abort idle3
So... I don't know how to fix it.
Help
Or maybe there's something similar that I can use?
report: https://app.box.com/s/u1wm8wf3iqqtr6tebrbofo07pbx0ydta
If you install 3.9.1 directly from python.org, which is the first release of python to support Mac OS X Big Sur, it will install with its own and newer version of tcl/tk (v8.6) and will install a working IDLE at the same time. IDLE will also become visible in Spotlight Search, putting an end to having to fire up Terminal every time :-)

What's the difference between homebrew python and caskroom python?

The page Installing Python on Mac OS X suggests that the OS X version is OK for learning but not great for writing real programs; solution - install from Homebrew.
I don't think the caskroom existed when they wrote this page though. Basically, I just want to install the most optimal version for doing Python programming.
When I do a search I get this output:
$ brew search python
boost-python gst-python python python3 wxpython zpython
Caskroom/cask/mod_python homebrew/python/vpython Caskroom/cask/python
homebrew/python/python-dbus homebrew/versions/gst-python010 Caskroom/cask/python3
This is what homebrew reports:
macosx-10-9:~ vagrant$ brew cask info python
python: 2.7.9
Python
https://www.python.org/
Not installed
https://github.com/caskroom/homebrew-cask/blob/master/Casks/python.rb
==> Contents
python-2.7.9-macosx10.6.pkg (pkg)
macosx-10-9:~ vagrant$ brew info python
python: stable 2.7.10 (bottled), HEAD
Interpreted, interactive, object-oriented programming language
https://www.python.org
/usr/local/Cellar/python/2.7.10_2 (4906 files, 77M) *
Poured from bottle
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/python.rb
So, what's the effective difference between these two packages?
Caskroom python installs the Python Mac OS X packages from https://www.python.org/downloads/mac-osx/ as they are provided there.
brew install python will install from source and under /usr/local/Cellar/python/... and properly symlink /usr/local/bin/python.
The latter is the "proper homebrew approach" (TM) and will allow updates with brew upgrade.

Homebrew failing to install postgresql; python 64-bit errors

I'm getting errors when running
$ brew install postgresql
==> Downloading http://ftp.postgresql.org/pub/source/v9.1.2/postgresql-9.1.2.tar.bz2
File already downloaded in /Users/neil/Library/Caches/Homebrew
Warning: Detected a framework Python that does not have 64-bit support in:
/Library/Frameworks/Python.framework/Versions/Current/Python
e configure script seems to prefer this version of Python over any others,
you may experience linker problems as described in:
http://osdir.com/ml/pgsql-general/2009-09/msg00160.html
fix this issue, you may need to either delete the version of Python
own above, or move it out of the way before brewing PostgreSQL.
te that a framework Python in /Library/Frameworks/Python.framework is
e "MacPython" version, and not the system-provided version which is in:
/System/Library/Frameworks/Python.framework
==> ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.1.2 --datadir=/usr/local/Cellar/postgresql/9.1.2/shar
^C
Here's where python is located.
$ which python
/usr/local/bin/python
I modified my ~/.zshrc PATH from
export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
to
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin
And although I'm getting python 64-bit errors, my version of python is 64-bit according to this SO post:
$ python -c 'import struct;print( 8 * struct.calcsize("P"))'
64
The problem pointed out in the referenced mailing list post is that the configure step isn't impacted by the PATH here. There's a whole other mechanism used to find things to link against; see Where do I set DYLD_LIBRARY_PATH on Mac OS X for a quick intro. You could try the suggested workaround given by the brew script--rename /Library/Frameworks/Python.framework/Versions/Current/Python to something else to get it out of the linker's search path, repeat the brew install, then put it back.
If you don't need Python bindings in your PostgreSQL, you can also just install it without Python bindings using brew install postgresql --no-python.
This command is installing the server, not the python bindings. Is that what you want? There is a installer for osx that will install the server for you.
Once you have done that, you can install the psycopg2 bindings directly from source.

Setuptools not found

I am switching from Linux to OSX and when I run our build's setup.py script, I get an error message that contains the text
This script requires setuptools version 0.6c7.
I have tried several times to install setuptools, and have verified that the setuptools egg exists in /Library/Python/2.6/site-packages. I have no idea why it is not being recognized.
It is very common to have multiple versions of Python on OS X systems. In recent releases of OS X, Apple has shipped two versions itself (in /usr/bin). You may have installed more recent versions using installers from python.org (which generally exist in /Library/Frameworks/Python.framework or using a package distributor like MacPorts (which install in /opt/local/Library/Frameworks/Python.framework). Keep in mind that each version of Python requires its own copy of setuptools.
Since the site package path you report is /Library/Python/2.6/site-packages, it is most likely you have used the Apple-supplied Python 2.6.1 in OS X 10.6 to try to install a new version of setuptools. Note that Apple already supplies setuptools for its Pythons (0.6c9 for 2.6.1 in 10.6); the corresponding easy_install commands are in /usr/bin.
$ /usr/bin/python2.6 -c 'import setuptools;print(setuptools.__file__,setuptools.__version__)'
('/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/__init__.pyc', '0.6c9')
If you are using another non-Apple-supplied Python, follow the instructions to install a new version of setuptools (or Distribute) making sure you are invoking the right version of Python. Check your shell PATH and which python to make sure.
If that doesn't help, update your question with more information.
UPDATE: Based on your further comments, it seems something was amiss in your default site-packages directory. With that problem out of the way and having established that there is an Apple-supplied setuptools version 0.6c9 installed, it appears the package you are trying to install is looking for a specific, earlier version of setuptools, 0.6c7. If that is the case, you should first determine why that is and if it is necessary. Chances are that it is just an incorrect version specification in the package's setup.py file, i.e. using == rather than >=. If you can, edit the setup.py so it can use a newer version. In the unlikely event that the package really does need that specific older version of setuptools (which may not even work with that version of Python or OS X), you could try installing the older version, like so:
$ sudo /usr/bin/easy_install-2.6 setuptools==0.6c7
$ /usr/bin/python2.6 -c 'import setuptools;print(setuptools.__file__,setuptools.__version__)'
('/Library/Python/2.6/site-packages/setuptools-0.6c7-py2.6.egg/setuptools/__init__.pyc', '0.6c7')
But you really should avoid doing that if at all possible as that will install another older version of easy_install in /usr/local/bin and could cause problems with installing and using other packages.
Have you tried to import setuptools in your setup.pyscript?
import setuptools
This solved my setuptool-ish build problems in the past.

Categories