Emacs和Conda解决方法 [英] Emacs and conda workaround
问题描述
我正在使用emacs和anaconda。
I'm using emacs and anaconda.
我在init.el中有此文件:
I have this in my init.el:
(setenv "WORKON_HOME" "/home/user/anaconda3/envs/")
和我路径上的conda:
And conda on my path:
# added by Anaconda3 installer
export PATH="/home/user/anaconda3/bin:$PATH"
但是emacs找不到我的conda环境,我理解它应该能够执行。
but emacs can't find my conda environments, which I understand it is supposed to be able to do..
因此,当我运行 Cc Cp
启动一个新会话和 Cc Cc
,它无法导入我的安装在conda环境中的包,并带有 ModuleNotFoundError
。
So, when I run C-c C-p
to start a new session, and C-c C-c
, it fails to import my packages which are installed in a conda environment, with ModuleNotFoundError
.
由于我已将其添加到路径中,但仍然无法正常工作,因此我正在尝试解决此问题,并且仍然能够从emacs运行我的conda应用程序。
Since I have added this to my path and it still doesn't work, I am trying to work around this, and still be able to run my conda applications from emacs.
我可以使用 Mx shell
然后在<$中打开emacs中的 shell c $ c> source激活myenv ,然后运行 python
。
I can open a shell in emacs with M-x shell
, then source activate myenv
, and run python
.
我现在想将 C-c C-c
复制到/ this / shell 中。我如何将这个 shell buffer 标记为python进程,以将我的file.py的文本发送到Cc Cc上,而不只是一个shell shell ?
I now want C-c C-c
to copy into /this/ shell. How do I mark this shell buffer as a python process to send my file.py's text to on C-c C-c, rather than just a shell shell?
我还查看了以下参考文献:
I've also looked at the following references:
- https:// emacs。 stackexchange.com/questions/20092/using-conda-environments-in-emacs
- conda-env列表/ conda信息--envs如何找到环境?
- https://emacs.stackexchange.com/questions/20092/using-conda-environments-in-emacs
- How does conda-env list / conda info --envs find environments?
但是这两个软件包都不适合我。当我尝试时,我仍然得到:
But neither package works for me. I still get, when I try:
conda-env-list
*Conda envs*
产生一个空白缓冲区。
对于pyvenv-workon:
And this for pyvenv-workon:
pyvenv-workon
Work on: (empty)
这些环境非常存在,如果我无法运行代码,就不可能将emacs用作python IDE。
These environments very much exist, and it makes it impossible to use emacs as a python IDE if I can't run my code.
推荐答案
我发现对我有用的是使用ELPA的 conda
软件包并设置其两个配置变量以指向我的Conda目录。以下代码片段在我的 .emacs
中起到了作用:
What I found works for me is to use the conda
package from ELPA and set two of its configuration variables to point to my Conda directory. The following snippet does the trick in my .emacs
:
(use-package conda
:ensure t
:init
(setq conda-anaconda-home (expand-file-name "~/miniconda3"))
(setq conda-env-home-directory (expand-file-name "~/miniconda3")))
-
conda-anaconda-home
等效于ANACONDA_HOME
环境变量(即包含您的Anaconda安装的所有文件) -
conda-env-home-directory
-是存储虚拟环境的目录(在envs
子目录中) conda-anaconda-home
is the equivalent to theANACONDA_HOME
environment variable (i.e. contains all files of your Anaconda installation)conda-env-home-directory
- is the directory where your virtual environments get stored (within theenvs
subdirectory)
使用此配置,我可以运行 Mx conda-env-activate 并有权访问所有以前创建的环境。
With this configuration I'm able to run M-x conda-env-activate and have access to all previously created envs.
这篇关于Emacs和Conda解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!