You can conffigure elpy-rpc-python-command. If you want Python3 you can set it like this.
(setq elpy-rpc-python-command "python3")
Create python3 virtualenv using virtualenvwrapper from terminal
$ mkvirtualenv test -p /usr/bin/python3
and then install required packages
$ pip install rope jedi importmagic autopep8 flake8
Now go to emacs, ...
When you spot a problem in the way how emacs behaves and if that happens only when you load your emacs config (init.el or .emacs) and not when you run emacs -Q, you need to bisect your init to find the culprit as @Drew mentioned in the comments.
Fortunately, you don't have to bisect your init in this case as you have a tangible visual clue of the problem.
If you want to customize per project basis, you can create a setup.cfg with custom config like this
max-line-length = 160
If you want to change this globally, you can change flake8 config as mentioned here https://flake8.pycqa.org/en/latest/user/configuration.html#user-configuration
You can solve this by modifying the python shell configuration from python to python3 in elpy-config
M-x elpy-config to enter the configuration page of elpy
if you scroll down you will see groups with [+] signs, toggle the Python one and find the shell interpreter option: Option Python Shell Interpreter is the one you are looking for.
If you click (or Enter ...
flymake uses flake8 to check the errors, so you have to tell flake8 which errors you don't want to see. You can do that globally by creating the file ~/.config/flake8, with the following content:
ignore = E303
You can also create a setup.cfg at the root of your project, with the same syntax, to have different settings per project.
Make sure to ...
I don't use eply, I use emacs 25.1.1 with company-jedi with the following:
python-shell-interpreter-args "--simple-prompt --pprint")
Inside emacs *Python*
Python 3.6.0, Anaconda 4.3.0, Ipython 5.1.0
In: x = 10
In: x = 125
In: x = # type M-p
I get history items 1 and 2 and Input restored.
The author of elpy suggests doing this via an advice, because elpy-enable modifies the python-mode-hook variable, so calling it inside the mode-hook is too late: https://github.com/jorgenschaefer/elpy/wiki/Configuration
(advice-add 'python-mode :before 'elpy-enable)
(use-package elpy :ensure t
Reading the docstring for the deprecated elpy-use-ipython, it points to https://elpy.readthedocs.io/en/latest/ide.html#interpreter-setup that recommends the following setup for ipython:
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args "-i --simple-prompt")
If it still fails, you could try using full path to your ipython ...
rgrep takes as its second argument file description in a format similar to shell globbing, which also exists in other languages, for example, in Python.
There's also a useful variable in Emacs related to rgrep: grep-files-aliases, which can be customized to alias various file groups, for instance
(push (cons "pyml" "*.py *.htm *.html") grep-files-aliases)
Well I figured it out:
kill-process kills the process as a side effect, so it returns before that is really killed. So a function like this works:
(defun my-restart-python-console ()
"Restart python console before evaluate buffer or region to avoid various uncanny conflicts, like not reloding modules even when they are changed"
This should be fixed as of the docs
By default, Elpy tries to find the root directory of the current project (git, svn or hg repository, python package or projectile project) and starts the python interpreter here. This behaviour can be suppressed with the option elpy-shell-use-project-root.
The order seems to be projectile root, then python project, ...
There's a workaround suggested in https://github.com/jorgenschaefer/elpy/issues/1381#issuecomment-434313600
Adding (setq elpy-eldoc-show-current-function nil) to my emacs init file makes it stop happening for me. Good enough!
Elpy doesn't require emacs jedi package. Also they won't work well when both are configured. I guess there is some conflict between them.
Use only elpy and you should be able to get completion in rpc buffer.
I created an empty file with
this = 2
After sending this to python buffer with C-C C-c, if i switch to python buffer and type Foo. ...
elpy has a function elpy-open-and-indent-line-below which is binded to <S-return>.
After """, you can hit <S-return> to open new line and indent automatically. You can use this at the end of line.
Alternatively, you can bind return to this function.
(define-key elpy-mode-map (kbd "<return>") 'elpy-open-and-indent-line-below)
Have you tried to delete elpy package from M-x list-packages? You can do it by pressing d on the elpy package, and then pressing yes to confirm the action. If you already did that, you can go to ~/.emacs.d and delete the elpy folder created when you installed it. Hope this help you.
I haven't tried this thoroughly, but should work:
1. if region is active, evaluate it (this currently works), goto 3.
2. if region not active, evaluate current statement, goto 3.
3. Jump to the beginning of next paragraph
(defun python-shell-send-region-or-line nil
"Sends from python-mode buffer to a python shell, intelligently."
The problem is ultimately the result of misunderstanding how completion works with company mode. I temporarily solved it by adding an import statement to the top of the org-babel block.
That is, typing, say sys. and awaiting the completion candidates that come with the sys module proved fruitless. However, beginning that same org-babel block with
You can install jedi/yapf packages in a separate virtualenv and just add $VIRTUAL_ENV/lib/python*/site-packages/ to your PYTHONPATH or to your virtualenv using add2virtualenv. Make sure you are using the same Python version for both virtualenvs.
Alternatively, you can install Elpy and the other packages globally (or user-local) and use the --system-site-...
You should create in your home folder a .flake8rc file, and add some content to ignore that error - documented here and below is a small template:
# it's not a bug that we aren't using all of hacking
# F812: list comprehension redefines ...
# H101: Use TODO(NAME)
# H202: assertRaises Exception too broad
You should be able to just enable company-mode globally without any problems with Elpy (if there are any, please do file a bug report!).
You can also use auto-complete in buffers other than Python mode buffers (auto-complete supports different backends from company-mode, so might be preferable for some), by removing python-mode from ac-modes. This will then ...
Elpy knows of two "roots" for your directory, the "project root" and the "library root". The project root is used for file searches and similar, while the library root is the directory added to sys.path.
In your example, my_project/ should be the project root, while my_project/src/ should be the library root. You can verify this using M-: (elpy-project-root)...
This seems to be bug in emacs and its fixed in this commit.
As npostavs mentioned, you can use
(defun python-shell-completion-native-try ()
"Return non-nil if can trigger native completion."
(let ((python-shell-completion-native-enable t)
ipython 5.0.0 by defautl uses prompt_toolkit which is really nice in a terminal but uses special characters for colors and completion that screws emacs display. Eventually it should be fixed but for now I have this in my .emacs:
(setq python-shell-interpreter "ipython3"
python-shell-interpreter-args "--simple-prompt --pprint")
and run M-x run-...