Coder Social home page Coder Social logo

Comments (9)

tleonhardt avatar tleonhardt commented on May 19, 2024

@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.

ytfei avatar ytfei commented on May 19, 2024

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.

ytfei avatar ytfei commented on May 19, 2024

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.

tleonhardt avatar tleonhardt commented on May 19, 2024

@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.

ytfei avatar ytfei commented on May 19, 2024

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.

tleonhardt avatar tleonhardt commented on May 19, 2024

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.

tleonhardt avatar tleonhardt commented on May 19, 2024

Oh duh, you are already using brew. Did you try "brew install readline" to install the C lib?

from cmd2.

ytfei avatar ytfei commented on May 19, 2024

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.

tleonhardt avatar tleonhardt commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.