Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Emacs 28 and venv
#1
Question 
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 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 and python-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 the python-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 executedpython3 -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?
Reply
#2
something like this: https://github.com/jorgenschaefer/elpy ?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  The command python3 -m venv venv does not correctly set sys.path echeadle 2 2,694 Jul-25-2023, 10:41 AM
Last Post: Aften1961
  paths for venv Skaperen 5 1,833 Jun-14-2022, 10:04 AM
Last Post: snippsat
  venv conflict at shell prompt Skaperen 3 2,852 Feb-21-2019, 02:18 AM
Last Post: Larz60+
  PyCharm virtual environment (venv) issues? j.crater 1 2,281 Aug-14-2018, 10:22 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020