Skip to content

Python Virtual Environment

夏南瓜 edited this page Nov 1, 2022 · 5 revisions

Hacks

Using Python virtualenv to Segregate Dependencies from System.


This hack is possible because EAF respects the Environment of the terminal, so basically we can source any particular pyenv and then launch emacs within it. Feel free to add complexities to your custom scripts and lets try to keep this simple.

  1. Create a virtual environment and note its path, lets say your user is user and virtualenv is in pyenv directory, the source path will be, /home/user/pyenv/bin/activate.

  2. Create a simple script somewhere, and lets call it launcher.sh the job of launcher.sh is to source the virtualenv file and launch emacs, create launcher.sh with following content

source /home/user/pyenv/bin/activate
emacs &

(don't forget to chmod +x launcher.sh)

  1. Now you can create a desktop entry for this with the following content (creating desktop entry basically means creating a .desktop file and moving it to ~/.local/share/applications)
[Desktop Entry]
Name=Emacs (Custom)
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/home/user/launcher.sh
Icon=emacs
Type=Application
Terminal=false
Categories=Development;TextEditor;Utility;
StartupWMClass=Emacs

And save it in ~/.local/share/applications/EmacsCustom.desktop now you should be able to see the desktop entry in dash/rofi. If you feel like launching from commandline, even ./launcher.sh will work.

Setting an Explicit Python Path.


You can set an explicit python path as a simple way to run EAF without conflicts with existing conda/virtual environments.
EAF will interact with a specified python once you set eaf-python-command in your Emacs configuration.

For example

(setq eaf-python-command "/usr/bin/python3")  ; this path needs to be changed based on your OS