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.
Related
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"))
I am working with `
Windows + CUDA 6.5 + VS2010 + Python2.7 + Theano.
My Python scripts works well when using command line, say:
python DDI_convnet.py
and I get results as:
However, when I run the same Python scripts in Eclipse, I get a lot of errors:
I think this is probably due to the difference of character Map of Eclipse and CMD, because the warning C4819 implies that a lot of .h files are not parsed correctly. How to fix it?
I find the answer myself. This is because, I installed Microsoft C++ for Python first, and then installed VS2010. The environment variable of Eclipse can only be updated after restarting windows.
However, after I restart windows, the problem changes, not warning C4819 any more, it began to report errors like "unresolved external ...", which is mainly due to some DLLs or libs are not included correctly by Eclipse.
Finally, I decide to change my IDE to PyCharm. Everything goes well so far.
I guess your system setting of 'system locale' is Chinese. Change it to English could possibly fix this problem.
https://stackoverflow.com/a/37871883/3148107
I'm using Sublime Text 3 With Pylinter to run pylint on my files.
However, on the same machine, I work on files for both python 2, and python 3 projects (the code is executed on one of several remote test-VMs, via SSH. I'm modifying the files by opening them over SMB. This is my home test-lab, and I'm finally sitting down to learn py3k).
Can I easily override the mechanism pylint uses to determine the python version it should lint for? Ideally, there would be an inline directive, but I have not had much luck finding anything.
I'm (editing) on Windows (the remote VMs are linux, but that' irrelevant here), for what it's worth.
You can try python2 -m pylint ... and python3 -m pylint .... That ensures that you use the right version.
AFAIK Pylint lints for the version of Python it is running on and it is not possible to override it.
Expanding on #sthenault's answer and borrowing heavily from #simon's to a very similar question on askubuntu, the solution is to write a wrapper script around pylint that executes it with the appropriate version of the Python interpreter. Drop the following into a script called mypylint (or whatever) somewhere in your $PATH:
#! /usr/bin/env bash
python_interpreter="python${1}"
pylint_args="-f colorized ${#:2}"
pylint_import=$(cat << PYTHON
import sys
import pkg_resources
__requires__ = "pylint"
sys.exit(
pkg_resources.load_entry_point("pylint", "console_scripts", "pylint")()
)
PYTHON
)
$python_interpreter -c "$pylint_import" $pylint_args
Then, execute it like so: mypylint 2|3 PYLINT_ARGS. For instance:
mypylint 2 -f colorized module.py
I'm not sure how you can tie that into sublime-text, but it more generally answers the question of parallel versions of pylint. I also bundled the above solution into a gist.
This is good, but I think the simplest thing is just to use virtualenv, and install pylint in each virtualenv. The correct pylint and python interpreter will be used.
You can override on a per-project level in Sublime Text by changing the pylint executable setting in Project->Edit Project to include:
"settings":
{
"SublimeLinter.linters.pylint.executable": ["py", "-3.4", "-m", "pylint"],
}
substituting 3.4 for your preferred flavour
You should have two pylint installations, say pylint2 and pylint3, then write a wrapper script that will subprocess the desired one.
You can install pylint3 which will evaluate for python 3.0, and pylint which will evaluate the code as python 2.7 by default.
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')
I'm using simplejson to get data from the New York Time API. It works when I run the file through the terminal with the command "python test.py" but not when I run through TextMate using command + R. I'm running the exact same file. Why is this?
I am running Snow Leopard 10.6.4, TextMate 1.5.10, and Python 2.6.4.
Edit: Sorry for forgetting to include this: by "doesn't work," I mean it says "No module named simplejson". I also noticed that this happens for PyMongo as well ("No module named pymongo").
What doesn't work? You should provide more information like error messages and what-not. However, I assume that the version of python is different, and simplejson isn't on your PYTHONPATH when launched from textmate.
Just so you know, simplejson was incorporated into the Python 2.6 distribution's standard library as json. So if you don't feel like wrestling with the import problem, try simply changing all your references to simplejson to json instead.
But, as suggested, this is going to turn out to be a PythonPath issue. Run these lines in the Python interpreter and from TextMate and compare the results.
import sys
print sys.path
To find out where simplejson is installed (if you don't know), do this in the Python interpreter:
import simplejson
print simplejson.__file__
If you want/need to set PYTHONPATH manually for TextMate, you can do that by adding it under Preferences > Advanced > Shell Variables.