Installed anaconda 3.x windows edition on a windows 7 desktop. I would like to be able to do vim style command line editing on the python interpreter started from a Cygwin shell.
I know Cygwin also comes with python and since I need to use the latest version of python I have a need to use the anaconda distribution of windows.
With anaconda windows image installed at /usr/local/anaconda3 went through info at Using the Python shell in Vi mode on Windows and did these steps
export CONDA_BASE_DIR=/usr/local/anaconda3
export SHELLOPTS
set -o igncr
export CONDA_DEFAULT_ENV=root
export CONDA_PREFIX=${CONDA_BASE_DIR}
cp /usr/local/anaconda3/Lib/site-packages/pyreadline/configuration/startup.py
/cygdrive/c/Users/my_windows_login
cp /usr/local/anaconda3/Lib/site-packages/pyreadline/configuration/pyreadlinecon
fig.ini
/cygdrive/c/Users/my_windows_login
export PYTHONSTARTUPPATH=c:\\Users\\my_windows_login\\startup.py
Edit /cygdrive/c/Users/my_windows_login/pyreadlineconfig.ini to uncomment
set_mode("vi")
history_filename("~/.pythonhistory")
history_length(200)
Starting up python interpreter as
$ conda activate base
(base) $ python -i $PYTHONSTARTUP
but vi editing mode is not enabled in command line of the interpreter as observed by hitting Esc-k.
Without -i flag, python windows binary will not startup in interactive mode in Cygwin environment. Since the interpreter when started with -i flag, does not read what is in $PYTHONSTARTUP, $PYTHONSTARTUP is explicitly specified in command line so that the startup.py script can be executed at startup time.
Downloaded
winpty-0.4.3-cygwin-2.8.0-x64.tar.gz
from
https://github.com/rprichard/winpty/releases
and extracted it to /usr/local of cygwin installation.
readline config needs to be in $HOME of cygwin as opposed to c:\\users\\<my_windows_login>
$ cp /usr/local/anaconda3/Lib/site-packages/pyreadline/configuration/startup.py $HOME
$ cp /usr/local/anaconda3/Lib/site-packages/pyreadline/configuration/pyreadlineconfig.ini $HOME
With above setup, when I run anaconda python as
$ PATH=/usr/local/anaconda3/Library/bin:$PATH winpty /usr/local/anaconda3/python
vi style command line editing works fine.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.