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:
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, andvirtualenv
is not installed. - The
python
command points to a Python version lower than 3.3 (beforevenv
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.
(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.