我在用emacs和anaconda。
我在我的init.el里有这个:
(setenv "WORKON_HOME" "/home/user/anaconda3/envs/")
康达在我的路上:
# added by Anaconda3 installer
export PATH="/home/user/anaconda3/bin:$PATH"
但是emacs找不到我的conda环境,我知道它应该能够做到。
因此,当我运行C-c C-p
来启动一个新会话,并运行C-c C-c
时,它无法导入安装在conda环境中的包,这些包是用ModuleNotFoundError
安装的。
因为我已经将它添加到我的路径中,但是它仍然不起作用,所以我试图解决这个问题,并且仍然能够从emacs运行我的conda应用程序。
我可以用M-x shell
,然后source activate myenv
,在emacs中打开一个shell,然后运行python
。
我现在希望C-c C-c
复制到/this/ shell中。如何将此shell缓冲区标记为python进程,以将文件my的文本发送到c C-c上,而不仅仅是shell shell
Update1
我还查看了以下参考资料:
但这两个包裹对我都不管用。我还是明白,当我试着:
conda-env-list
*Conda envs*
生成空白缓冲区。
这是给化工厂的:
pyvenv-workon
Work on: (empty)
这些环境非常存在,如果我不能运行代码,就不可能将emacs作为python使用。
发布于 2019-03-15 14:17:55
程序从生成它们的shell继承环境变量。conda和virtualenv的工作方式是重写shell的PATH变量。他们这样做是为了让操作系统找到新版本的应用程序(conda或virtualenv),而不是安装在操作系统中的默认版本(Macs附带了一个古老版本的python)。
那么,这里发生了什么?如果通过双击OS图标启动Emacs,它将继承默认的shell环境变量。因此,当您试图调用您用conda安装的库(或等效地使用virtualenv和pip)时,因为您使用的是默认OS路径,操作系统将查找python的默认版本(以及关键是默认版本的库)。默认版本的python将响应“我不知道它是什么库”。
怎么修?一种可靠的方法是不通过双击OS启动Emacs。以下是我大多数日子所做的事情:
1) start a console/terminal
2) switch to the conda environment `activate py37`
(or with virtualenv: `source .py37dev/bin/activate`)
3) start Emacs from that same shell that has the modified environment variables.
On a Mac its: `/Applications/Emacs.app/Contents/MacOS/Emacs`
(I use a installed version of Emacs on the Mac because the one that
comes with Mac is ancient).
On Linux and Windows the path to EMacs will be different but the idea is the same.
4) start a shell inside Emacs and you should see the shell looks the way it does
in your conda shell (or virtualenv shell)
在这里,它对我来说是什么样子:
看看python的版本如何不是默认的OS?它来自虚拟环境(conda的工作方式完全相同,start环境是一个不同的命令)
发布于 2020-04-17 20:06:08
我测试了Wojciech Gac、Mittenchops和James Anderson的答案中给出的解决方案。
虽然James Anderson's solution的解决方案到目前为止是最简单的,但它也有一些问题:首先,您必须重新激活在emacs中生成的每个shell进程中的环境。还有一种可能是emacs有不同的pythonpath,因此不情愿地使用系统python而不是venv
python。
使用conda.el
的解决方案有点奇怪。在Melpa中,它被列为过时的,使用https://github.com/necaris/conda.el的指令,它将无法识别我特定机器上的环境。
在同一台机器上,使用pyenv
的解决方案就像https://emacs.stackexchange.com/a/20093/28567中提到的那样,工作起来很有魅力。
因此,您只需要使用M-x package-install
安装pyenv
搜索,然后将以下两行插入.emacs
(setenv "WORKON_HOME" "~/anaconda3/envs") ; /anaconda3 || /miniconda || wathever path your conda installation is located at
(pyvenv-mode 1)
发布于 2020-06-03 09:47:54
这是我对这个问题的最低限度的解决方案:
创建这样的批处理文件
conda activate <yourEnv>
python -i
设置(本地)python-shell解释器,指向批处理文件。
像往常一样运行python( C-p .)
https://stackoverflow.com/questions/55175916
复制相似问题