Comments (9)
@ytfei Can you provide any more information about the environment you are running in? Knowing the operating system, version of Python, and terminal program you are using would be extremely helpful.
The ability to show the previous command by pressing the up arrow is handled by the Readline library or an equivalent. If you are using a major Linux distro like Ubuntu, Debian, Mint, Fedora, Redhat etc. then the readline library should be installed out-of-the-box (though this probably doesn't apply to minimalistic distros like Arch).
For other OSes, you may need to install an additional library, depending on how you installed Python. See the note on the 1st page of the documentation for specific recommendations:
https://cmd2.readthedocs.io/en/latest/
from cmd2.
thanks @tleonhardt . I'm running in macOS, iTerm2.
And I've installed readline (6.2.4.1)
with pip.
python --version
Python 2.7.11
pip list | grep readline
readline (6.2.4.1)
Python is installed with brew.
from cmd2.
According to https://cmd2.readthedocs.io/en/latest/ I installed gnureadline
➜ tmp pip install gnureadline
Requirement already satisfied: gnureadline in /usr/local/lib/python2.7/site-packages
➜ tmp pip install cmd2
Collecting cmd2
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from cmd2)
Requirement already satisfied: pyparsing>=2.0.1 in /usr/local/lib/python2.7/site-packages (from cmd2)
Installing collected packages: cmd2
Successfully installed cmd2-0.7.0
➜ tmp cat demo.py
from cmd2 import Cmd
class App(Cmd):
pass
app = App()
app.cmdloop()
➜ tmp python demo.py
(Cmd) help
Documented commands (type help <topic>):
========================================
_relative_load edit help list pause quit save shell show
cmdenvironment eof history load py run set shortcuts
(Cmd) ^[[A
Still got ^[[A
when i pressing the up arrow
from cmd2.
@ytfei Interesting. Your setup is pretty similar to mine actually. I'm running on a Mac and use a mix of Python 3.6 and 2.7, both installed via Anaconda and switch between them using conda envs. In both cases, cmd2 and readline function nicely together. And I always use iterm2.
Can you try going into a python/ipython shell and do this:
import readline
readline._READLINE_VERSION
from cmd2.
well, seems readline
couldn't work.
➜ tmp pip uninstall readline
Uninstalling readline-6.2.4.1:
/usr/local/lib/python2.7/site-packages/readline-6.2.4.1.dist-info/DESCRIPTION.rst
/usr/local/lib/python2.7/site-packages/readline-6.2.4.1.dist-info/INSTALLER
/usr/local/lib/python2.7/site-packages/readline-6.2.4.1.dist-info/METADATA
/usr/local/lib/python2.7/site-packages/readline-6.2.4.1.dist-info/RECORD
/usr/local/lib/python2.7/site-packages/readline-6.2.4.1.dist-info/WHEEL
/usr/local/lib/python2.7/site-packages/readline-6.2.4.1.dist-info/metadata.json
/usr/local/lib/python2.7/site-packages/readline-6.2.4.1.dist-info/top_level.txt
/usr/local/lib/python2.7/site-packages/readline.so
Proceed (y/n)? y
Successfully uninstalled readline-6.2.4.1
# reinstall
➜ tmp pip install --force-reinstall readline
Collecting readline
Installing collected packages: readline
Successfully installed readline-6.2.4.1
➜ tmp python
Python 2.7.11 (default, Dec 26 2015, 17:47:53)
[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 readline
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so, 2): Library not loaded: /usr/local/opt/readline/lib/libreadline.6.dylib
Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so
Reason: image not found
>>>
from cmd2.
That looks like you have the Python readline module installed but not the C library which it relies on.
I've found using pip on a Mac to be unreliable unless you also have GCC installed via Homebrew. I typically use Python installed via the Anaconda distro and then use the conda package manager which comes with it for installing packages whenever possible and pip only when I can't get it from conda. This has given me a much happier Python experience:
https://www.continuum.io/downloads
Alternatively, sometimes I use Homebrew package manager to install the underlying C libraries necessary:
https://brew.sh
Would you be game for trying any of the above @ytfei ?
from cmd2.
Oh duh, you are already using brew. Did you try "brew install readline" to install the C lib?
from cmd2.
Thanks very much @tleonhardt . I finally fixed it with your help.
The problem is i had two readline
lib installed (6.3.8, 7.0.3_1) and the default one was set to 7.0.3_1
. but when i execute import readline
, it always looking for 6.3.8 which is not in the lib path.
from cmd2.
Your welcome @ytfei. Glad your problem is solved.
By the way, if your native language is not English, you may wish to use cmd2 with Python 3 as that way you will get full unicode support.
from cmd2.
Related Issues (20)
- updating the prompt overwrites incremental search HOT 1
- Can I call Command Scripts from python code? HOT 1
- cmd2 and a-Shell HOT 7
- Edit auto complete in a specific directory HOT 1
- poutput() and ansi styles.
- tttt HOT 1
- Adding a did you mean? or most similar command in case of error HOT 10
- Typing problem: use of @with_argparser will cause mypy to issue an error HOT 4
- New versions of Statekeeper, ParsedString HOT 3
- Generates an AttributeError when used in a pyinstaller-packaged application HOT 3
- mypy since 1.6.0 introduces validation error
- Allow class member method to be argparse factory
- comments are not stripped when a command is decorated by "cmd2.with_argparser" HOT 1
- onecmd returns False if command returns None, different from cmd module behavior
- Persistent history file not saved when application is killed HOT 2
- how to save the Settable HOT 2
- Can't run first application example HOT 1
- readline history is fragmented when using multiline commands
- vertically help menu HOT 2
- Getting extra quotes when tab autocomplete(behaviour different when compared with cmd) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cmd2.