1

I am running emacs-28.1 and starting of with elpy. My current python development section is as follows:

(use-package elpy
  :ensure t
  :defer t
  :init
  (setq elpy-rpc-python-command "python3")
  (setq elpy-rpc-virtualenv-path 'current)
  (add-hook 'elpy-mode-hook
        (lambda() (setq display-line-numbers 'relative)))
  (advice-add 'python-mode :before 'elpy-enable))
  ;;(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save))


(use-package pyvenv
  :ensure t
  :config
  (pyvenv-mode t)

  ;; Set correct python-interpretor
  (setq pyvenv-post-activate-hooks
    (list (lambda ()
        (setq python-shell-interpreter (concat pyvenv-virtual-env "bin/python3")))))
  (setq pyvenv-post-deactivate-hooks
    (list (lambda ()
        (setq python-shell-interpreter "python3"))))

  ;; Taken from "https://medium.com/analytics-vidhya/managing-a-python-development-environment-in-emacs-43897fd48c6a"
  (setq pyvenv-use-alias 't)
  (setq pyvenv-set-path nil)

  ;;(global-pyenv-mode)
    (defun pyenv-update-on-buffer-switch (prev curr)
      (if (string-equal "Python" (format-mode-line mode-name nil nil curr))
          (pyenv-use-corresponding)))
    (add-hook 'switch-buffer-functions 'pyenv-update-on-buffer-switch))


(provide 'pydev)

My elpy-config output is as follows,

Elpy Configuration

Emacs.............: 28.1
Elpy..............: Not found (Python), 1.35.0 (Emacs Lisp)
Virtualenv........: pyMachine (/home/bussler/VirtualEnvs/pyMachine/)
Interactive Python: /home/bussler/VirtualEnvs/pyMachine/bin/python3 3.10.5 (/home/bussler/VirtualEnvs/pyMachine/bin/python3)
RPC virtualenv....: pyMachine (/home/bussler/VirtualEnvs/pyMachine)
 Python...........: python3 nil (/home/bussler/VirtualEnvs/pyMachine/bin/python3)
 Jedi.............: Not found
 Rope.............: Not found
 Autopep8.........: Not found
 Yapf.............: Not found
 Black............: Not found
Syntax checker....: flake8 (/home/bussler/VirtualEnvs/pyMachine/bin/flake8)

Warnings

The Python interpreter could not find the elpy module. Please report
to: https://github.com/jorgenschaefer/elpy/issues/new.

There was an unexpected problem starting the RPC process. Please check
the following output to see if this makes sense to you. To me, it
doesn't.

<string>:3: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
{"can_connect_to_pypi": true, "rpc_python_version": "3.10.5", "elpy_version": "1.35.0", "jedi_version": "0.18.1", "jedi_latest": null, "rope_version": "1.2.0", "rope_latest": null, "autopep8_version": "1.6.0", "autopep8_latest": null, "yapf_version": "0.32.0", "yapf_latest": null, "black_version": "22.6.0", "black_latest": null}

However, I have elpy installed in emacs and Jedi installed in virtual environment. I am just starting to use emacs for my python development. Could someone shed some light as to what am I doing wrong (or) missing?

I am having company-mode for my auto-complete for other languages, haskell and rust. I am finding hard to have it work for python (as I copied the code-snippets for haskell and rust from web. Any suggestion/help would be much appreciated.

elpy-config output after editing the elpy.el file under ~/.emacs.d/elpa/elpy-1.35 as follows:

(defvar elpy-config--get-config "import json
import sys
from distutils.version import LooseVersion
import warnings
warnings.filterwarnings('ignore', category=FutureWarning)

import requests

# Two sections commented below are default
# Chaged urllib2 to urllib3
# try:
#     import urllib3 as urllib
# except ImportError:
#     import urllib.request as urllib


# Check if we can connect to pypi quickly enough
# try:
#     response = urllib.urlopen('https://pypi.org/pypi', timeout=1)
#     CAN_CONNECT_TO_PYPI = True
# except:
#     CAN_CONNECT_TO_PYPI = False


# Adopted from 
# https://github.com/jorgenschaefer/elpy/issues/1588
def latest(package, version=None):
    try:
        response = requests.get('https://pypi.org/pypi/{package}/json'.format(package=package)).content
        latest = json.loads(response)['info']['version']
        if version is None or LooseVersion(version) < LooseVersion(latest):
            return latest
        else:
            return None
    except:
        return None

# This is the default code
# def latest(package, version=None):
#     if not CAN_CONNECT_TO_PYPI:
#         return None
#     try:
#         response = urllib.urlopen('https://pypi.org/pypi/{package}/json'.format(package=package),
#                timeout=2).read()
#         latest = json.loads(response)['info']['version']
#         if version is None or LooseVersion(version) < LooseVersion(latest):
#             return latest
#         else:
#             return None
#     except:
#         return None
. . .

My elpy-config output is below:

Elpy Configuration

Emacs.............: 28.1
Elpy..............: Not found (Python), 1.35.0 (Emacs Lisp)
Virtualenv........: pyMachine (/home/bussler/VirtualEnvs/pyMachine/)
Interactive Python: /home/bussler/VirtualEnvs/pyMachine/bin/python3 3.10.5 (/home/bussler/VirtualEnvs/pyMachine/bin/python3)
RPC virtualenv....: pyMachine (/home/bussler/VirtualEnvs/pyMachine)
 Python...........: python3 nil (/home/bussler/VirtualEnvs/pyMachine/bin/python3)
 Jedi.............: Not found
 Rope.............: Not found
 Autopep8.........: Not found
 Yapf.............: Not found
 Black............: Not found
Syntax checker....: flake8 (/home/bussler/VirtualEnvs/pyMachine/bin/flake8)

Warnings

The Python interpreter could not find the elpy module. Please report
to: https://github.com/jorgenschaefer/elpy/issues/new.

There was an unexpected problem starting the RPC process. Please check
the following output to see if this makes sense to you. To me, it
doesn't.

<string>:3: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
{"can_connect_to_pypi": true, "rpc_python_version": "3.10.5", "elpy_version": "1.35.0", "jedi_version": "0.18.1", "jedi_latest": null, "rope_version": "1.2.0", "rope_latest": null, "autopep8_version": "1.6.0", "autopep8_latest": null, "yapf_version": "0.32.0", "yapf_latest": null, "black_version": "22.6.0", "black_latest": null}

Elpy could not connect to Pypi (or at least not quickly enough) and
check if the python packages were up-to-date. You can still try to
update all of them:

[Update python packages]

The Jedi package is not currently installed. This package is needed
for code completion, code navigation and access to documentation.

[Install jedi]

No autoformatting package is currently installed. At least one is
needed (Autopep8, Yapf or Black) to perform autoformatting (`C-c C-r
f` in a python buffer).

[Install autopep8]
[Install yapf]
[Install black]

No change, however.

2

1 Answer 1

1

The package elpy should be installed in folder elpa, not in virtual environment. It is of same rank and functionality as company package, for instance. The package python should be loaded before elpy(aka you must load it in your emacs, with (use-package 'python). Try to delete all caches and the virtualenv created if you moved elpy to folder elpa.

But there are some problems with this package as follows:

  • As described here, this is not maintained at the moment; some small modifications are made however, from time to time.

  • Read the file setup.cfg - this shows the package is valid for Python versions up to 3.4, or you are using the version 3.10. There is the risk to have false warning/errors for your code if you write something new/unknown for elpy, so a good idea is to avoid this package until it is up to date.

What can you do: see/install/use the eglot package, works OK out the box with the setting shown on that page.

Another solution is the Emacs LSP.

1
  • Yes, it's just incompatibility conflict among Python 3.10 and ELPA version of Elpy. Serendipitously I've found solution: elpy.readthedocs.io/en/latest/… Just check-out to the branch add-new-py-version
    – Alioth
    Dec 14, 2023 at 11:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.