ipython up and down arrow strange behaviour - python

In my installation of ipython I have this strange problem where I cannot reliably move through command history with up and down arrows... a lot of the time it just doesn't work (nothing happens on the key press). Also sometimes writing normal characters at the end of the command just doesn't work.
My system: Mac OSX Lion
I have readline installed...
thank you for the help!
david

Make sure you installed readline before ipython.
sudo pip uninstall ipython
sudo pip install readline ipython
(I know this question is a few months old, but for future reference)

I had to install readline with easy_install readline and that fixed it.
Using pip install readline did not work for me, and ipython gave a warning:
******************************************************************************
libedit detected - readline will not be well behaved, including but not limited to:
* crashes on tab completion
* incorrect history navigation
* corrupting long-lines
* failure to wrap or indent lines properly
It is highly recommended that you install readline, which is easy_installable:
easy_install readline
Note that `pip install readline` generally DOES NOT WORK, because
it installs to site-packages, which come *after* lib-dynload in sys.path,
where readline is located. It must be `easy_install readline`, or to a custom
location on your PYTHONPATH (even --user comes after lib-dyload).
******************************************************************************

Following trouble in iPython and up-&-down arrows to access history, and browsing this post, a simple solution (turn off "Scroll lock") turned out to work for me.

This is an intentional feature of IPython. If you type "abc" and then hit the up arrow, it's going to scroll only through lines that start with "abc". If you hit lift/right while you're scrolling, it triggers the same behavior. The entire contents of the current line are interpreted as your search prefix, any only lines starting with all that will show up on further up/down keypresses.
You can change this behavior in your PYTHONSTARTUP file. I have the following lines:
import readline
# Prevent ctrl-p/ctrl-n/Up/Down from doing prefix searching
readline.parse_and_bind('"\\C-p": previous-history')
readline.parse_and_bind('"\\C-n": next-history')
readline.parse_and_bind('"\\e[A": previous-history')
readline.parse_and_bind('"\\e[B": next-history')
If you're curious, here are the bindings in IPython's source code that we're overriding.
Unrelated, but I also like to to override readline's default ctrl-w:
# Ctrl-W behavior more like Vim
readline.parse_and_bind('"\\C-w": backward-kill-word')

Related

How to get my Vim and MacVim to find python3?

When I use a plugin that requires python, it can't find it and barfs.
The places that seem to being searched are:
Using -version I see both:
+python/dyn
+python3/dyn
However :echo has("python3") returns 0.
I'm not sure if this is compile time config, or runtime-configurable via .vimrc.
I'm not a python developer, and the few times I've ventured into that world were in the middle of the python2/python3 mess that turned me off completely. I've played around enough to have configured pyenv it seems, and get
╰─$ which python
/Users/benlieb/.pyenv/shims/python
╰─$ python --version
Python 3.10.3
Can anyone help shed light on what to do to get python3 findable/usable in my vim?
Update:
Following #romainl's suggestion below I set in my .vimrc
set pythonthreedll=/Users/benlieb/.pyenv/shims/python
But getting the following error:
+python/dyn and +python3/dyn are described here: :help python-dynamic.
By default, :help 'pythonthreedll' points to:
/opt/homebrew/Frameworks/Python.framework/Versions/3.10/Python
because MacVim is built against that version. The message in your screenshot says that there is nothing at that path. In order to have a working Python 3 interface, you can either:
install Python 3.10 via homebrew,
or point pythonthreedll to a valid path.
For example, I don't use Homebrew so the default value is useless to me, but I use MacPorts so this is my pythonthreedll:
set pythonthreedll=/opt/local/Library/Frameworks/Python.framework/Versions/3.10/lib/libpython3.10.dylib
After some time, I found the following works, thought it was not a fun path of discovery.
let &pythonthreedll = trim(system("pyenv which python"))

Installed Python 3.10.2 and now my Pip installs are not being found

Everything in my code was working perfectly fine up until I decided I wanted to utilize match-case in Python. Find out its only a thing in 3.10+, so I quickly install it and change it to be the interpreter in command palette.
Then I try to run my code same as before, and I'm not sure what changed but my Keyboard import is giving me 'Import "keyboard" could not be resolved'. Issues. The same issue was actually present as well with the 'from nis import match' module.
I installed keyboard initially using 'pip install keyboard' when running my 3.9 version, and legit everything was fine. This all started after I installed 3.10 (which I did from Pythons website yes); and I did add to PATH, but I dont think that would have any impact on my imports in VScode.
Confused as heck right now, please look at my screenshots for clearest explanation of what I'm facing.
Import could not be resolved
.
Module Not Found Error
.
pip3.10 show keyboard
.
My interpreter list from command palette
Any and all help appreciated, I'm extremely confused and think I've tried it all now
New Python versions use new site-packages folders. You need to reinstall everything. This is why poetry, pipenv, or requirements.txt are used
I think the linter-like extension/whatever Pylance is is the problem. Why? Because as we've tried, pip install keyboard and pip install --upgrade keyboard just confirm that the requirement is satisfied and the latest version of keyboard is already installed.
What I did was change Pylance's settings. Yes, it's not an actual error (with the code), but Pylance's problem. It just didn't see enough files in the keyboard package to satisfy its hunger, or Microsoft was just too lazy to pass more checks and update it accordingly, because however it happened, when I tried changing the setting to display an "error" at "missing imports" for fun, it didn't show errors or the default "warning" but "none", because I had run the file before I changed it back to display an error (maybe Pylance observed that when the file was run, there was no ModuleNotFoundError, and so stopped showing the warning).
I better shut now, because the setting I changed/overrode by adding it in settings.json is:
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
which is in:
{
...,
...,
...,
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
}
Here is a list of keys like "reportMissingImports" whose values you can change. These are the allowed values for the keys in python.analysis.diagnosticSeverityOverrides:
error (red squiggle)
warning (yellow squiggle)
information (blue squiggle)
none (disables the rule)
You would want to change their values only if you want to change their behaviour.
You can find settings.json by its path or by going to the settings GUI and clicking on any "Edit in settings.json" link-like button. You can also make settings.json open instead of the GUI by default.
Now, you won't see any more warnings when you import modules and can code without being anxious about the stupid warning.
Wow, So as it turns out, a solution I tried previously, to no avail is now working to solve this bizarre issue.
Simply put, I once again went to Command Palette (Ctrl+Shft+P), and looked through my interpreters I had to see what could be wrong.
Decided to click on the 'recommended' option I assumed I had been running this whole time. Turns out I was using this 'third' option as shown in the screenshot (the one not highlighted ofcourse); and it's the reason my module installs were being found on my machine, but not by the interpreter; as such giving me errors and not running the module for the program.
Simple error, but thanks to those who did help.

Python 3 Pyperclip Installed but Module not Found

I'm trying to copy some text to clipboad in my python program, so I've installed pyperclip via pip command via Windows command line interface, it says everything is successfully installed, not a problem. However, when I import the thing into my project, I get
from tkinter import *
from tkinter import ttk
import pyperclip
import binascii
#my code...
...
ModuleNotFoundError: No module named 'pyperclip'
So I was like *** that, maybe it's broken, I found a little library that does exactly the same, called "clipboard". Exactly the same installation procedure - from the command line. Same successful installation. Same ModuleNotFoundError. So clearly something wrong on my side, but I have no idea what it is, no idea where to look and what to do. I just want to be able to copy some text to clipboard. Multiplatform. That's it.
It's Python 3.8, Windows 10
pyperclip-1.8.0
pip-20.2.2
If I need to show you some logs or tell you something about my installation, please tell me what exactly to do and where to find information you may need. I'm good with instructions, but I don't have much (any) experience rummaging through logs and python installation folders.
Similar posts have slightly different problems, I didn't find any clear solution or hints that I could understand. No reply seemed like a solution to me.
Anyway, I would really appreciate any help from the community. Being unable to simply copy something to clipboard is killing me, especially since it's the only thing I can't implement. And it's just one function for one button to copy one short piece of text. It's like being stuck at 99% loading, when everything is done, and you just can't write the final line of code, haha.
Pycharm uses a virtualenv for pycharm projects. Navigate through:
Pycharm >> File >> Settings(or press Ctrl+Alt+S on win) >> Project:Name >> Project Interpreter >> Click on the plus(+) symbol above the scroll bar and type in pyperclip and press install package.
And this will install pyperclip for your Pycharm IDE. Since pycharm uses a virtual env for its projects you can change it in the project interpreter section as well, and then the pyperclip you installed from the cmd using pip, will be available to be used on that global version of python(now used by your Pycharm too).
If you still have any errors or doubts, do let me know :D
Cheers

Emacs 24's python.el + ipython cannot complete module names

I'm using Emacs 24.4.1 on OSX (installed with Homebrew), with the built in python.el, and Python 3 (also installed with Homebrew), along with IPython 2.3.0. I have this in my .emacs:
(setq
python-shell-interpreter "/usr/local/bin/ipython3"
python-shell-prompt-regexp "In \\[[0-9]+\\]: "
python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
python-shell-completion-setup-code
"from IPython.core.completerlib import module_completion"
python-shell-completion-module-string-code
"';'.join(module_completion('''%s'''))\n"
python-shell-completion-string-code
"';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
Everything works correctly when I invoke M-x run-python, except one thing: the <tab>-completion of module names doesn't work in the REPL (it says "No match" in the *Messages* buffer). I'm pretty sure it was working with Emacs 24.3, which I upgraded very recently, but I'm not 100% sure. Anyone has an idea what might cause this, or how I could try to debug it?
You might like to try and remove most of your settings above, since Emacs-24.4 should support IPython pretty much out of the box.

Potentially devious behaviour of pygments´ mapping.py / Editing a pygments lexer

I'm using Windows 7, latest windows update etc.
Recently I decided to start using the minted package in LaTeX. For this, I was redirected to install pygments, which I installed through pip:
I'll run you through quickly what I did (to make sure I didn't do anything wrong):
Installed python 3.4 from this page.
easy_install pip in the windows command prompt.
pip install pygments in command prompt.
I've added the %PYTHONPATH% as well as %PYTHONPATH%\Scripts (which is where pygments operates from I've been led to believe), to the system PATH environment.
I'm typing source code from R into LaTeX, but the releases I could find do not offer the capital R syntax. If I use LaTeX code as such:
\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}{R} % Capital R won't function as intended with recent release
c(1,2,5,7,8)
\end{minted}
\end{document}
It won't recognise the capital R argument in minted.
Now, the lower case \begin{minted}{r} works just fine, so I've looked around on how to fix this, and found this answer.
Here it is suggested to adjust the math.py lexer (at %PYTHONPATH%\Lib\site-packages\pygments\lexers) to add an alias 'R' to current aliases. It also suggests to run _mapping.py in the same directory (%PYTHONPATH%\Lib\site-packages\pygments\lexers). Running _mapping.py has two effects:
It completely empties the file, the file size is reduced to 0 bytes and editing it with IDLE confirms an empty file.
It also yields this error message.
Not running _mapping.py won't apply my new alias to pygments. Running it, breaks pygments entirely. The error code is shown below.
I ran the LaTeX code again (with changes and _mapping.py also run), with pdfLaTeX, with arguments: $synctexoption, --enable-write18, -interaction=nonstopmode and $fullname (also in this order), I get the following error in LaTeX:
LaTeX Error: File `temp.out.pyg' not found.
Type X to quit or <RETURN> to proceed,
or enter new name. (Default extension: out.pyg)
Enter file name:
! Emergency stop.
<read *>
l.64 \end{minted}^^M
After running _mapping.py on a clean installation even (no changes made to any lexer or anything), I also run into the same problem. I'm uncertain whether the initial changes I made, changed registry values and whatnot, but I'm having serious issues applying this simple change to the pygments lexer.

Categories