Skip to main content

Elpy RPC Process and Python Version

··2 mins·
Elpy Python Emacs
Makoto Morinaga
Author
Makoto Morinaga
A personal notebook for tech notes, coding, and system experiments.
Table of Contents

Errors related to the Python version used in Elpy’s RPC Process are discussed here.

Error
#

Elpy’s RPC Process creates a dedicated virtual environment by default in \~/.emacs.d/elpy/rpc-venv. However, in some environments, the following error may occur, preventing the creation of the virtual environment:

error
Elpy needs the 'virtualenv' or 'venv' python packages to create its virtualenv. Please install one of them or disable the dedicated virtualenv with '(setq elpy-rpc-virtualenv-path 'current)'

Possible Cause
#

This error occurs because Elpy references the python command by default when creating the virtual environment. If the corresponding command (virtualenv or venv) does not exist, the error may arise in the following cases:

  • The python command points to Python 2, and virtualenv is not installed.
  • The python command points to a Python version lower than 3.3 (before venv was integrated).

Solution
#

Since Python 2 support has ended, it is preferable to use Python 3 as the main version. The Python version used in Elpy’s RPC Process should be explicitly set to Python 3.

This can be specified using elpy-rpc-python-command, as shown below. If the python3 command is unavailable, install Python 3 on the system or specify an existing python3.x command.

~/.emacs.d/init.el
(setq elpy-rpc-python-command "python3")

This configuration is added to ~/.emacs.d/init.el.

Applying this setting ensures that Elpy uses Python 3’s venv to create the virtual environment for the RPC Process, resolving the error.

Reference
#

option-elpy-rpc-python-command

Related

Precautions with Default Arguments in Python
··2 mins
Python
Basics of Bitwise Enumeration
··2 mins
Algorithm Python
Summary of Underscore Usage in Python
··5 mins
Python