Nov-29-2022, 10:12 PM
I am hoping for a fellow Emacs user being here.
I would be very happy if something could explain to me dump terms how I get Emacs to be aware a standard Python venv using the default python-mode
Not third-party tools like pyenv, anaconda etc.
I found this explanation in python.el
I have lots of small "projects" all over the place I just created a directory and executed
I cannot import and modules from my venv in Emacs, even my I open a shell and activate the environment.
And hardcoding
So how do one use venv in Emacs?
I would be very happy if something could explain to me dump terms how I get Emacs to be aware a standard Python venv using the default python-mode
python.el
.Not third-party tools like pyenv, anaconda etc.
I found this explanation in python.el
Quote:Shell virtualenv support: The shell also contains support for
virtualenvs and other special environment modifications thanks to
python-shell-process-environment
andpython-shell-exec-path
.
These two variables allows you to modify execution paths and
environment variables to make easy for you to setup virtualenv rules
or behavior modifications when running shells. Here is an example
of how to make shell processes to be run using the /path/to/env/
virtualenv:
(setq python-shell-process-environment (list (format "PATH=%s" (mapconcat 'identity (reverse (cons (getenv "PATH") '("/path/to/env/bin/"))) ":")) "VIRTUAL_ENV=/path/to/env/")) (python-shell-exec-path . ("/path/to/env/bin/"))Since the above is cumbersome and can be programmatically
calculated, the variable `python-shell-virtualenv-root' is
provided. When this variable is set with the path of the
virtualenv to use,process-environment' and
exec-path` get proper
values in order to run shells inside the specified virtualenv. So
the following will achieve the same as the previous example:
(setq python-shell-virtualenv-root "/path/to/env/")Also thepython-shell-extra-pythonpaths
variable have been
introduced as simple way of adding paths to the PYTHONPATH without
affecting existing values.
Shell package support: you can enable a package in the current
shell so that relative imports work properly using the
python-shell-package-enable
command.
I have lots of small "projects" all over the place I just created a directory and executed
python3 -m venv venv
.I cannot import and modules from my venv in Emacs, even my I open a shell and activate the environment.
And hardcoding
python-shell-virtualenv-root
in my init file for every project I have and for future projects. Doesn't seem right, that can't be what it is for. So how do one use venv in Emacs?