激活anaconda环境和直接运行其python可执行文件有什么区别? [英] What is the difference between activating an anaconda environment and running its python executable directly?

查看:126
本文介绍了激活anaconda环境和直接运行其python可执行文件有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Anaconda设置了多个python环境.

I have setup multiple python environment using Anaconda.

通常,要手动"运行脚本,我将打开命令行,然后键入:

Usually, to run a script "manually", I would open a command line and then type:

activate my-env
python path/to/my/script.py

好.

现在,我正在尝试使用调度程序自动运行脚本,我想知道两者之间有什么区别

Now I am trying to run a script automatically using a scheduler and I was wondering what the difference was between

  1. 编写一个可以激活环境并执行脚本的批处理(如上面的代码段所示)

  1. Writing a batch which activates the environment and the executes the script (like in the snippet above)

从环境(在 envs/my-enjv/目录中)直接调用python可执行文件,如下所示:

Calling directly the python executable from the environment (within the envs/my-enjv/ directory) like below:

/path/to/envs/my-env/python.exe路径/to/my/script.py

两者似乎都可以正常工作.有什么区别吗?

Both seem to work fine. Is there any difference?

推荐答案

我并没有声称自己是专家,但这是我的2美分.

I don't claim to be an expert but here's my 2 cents.

对于小脚本,不,没有区别.

For small scripts, no, there isn't a difference.

调用外部模块/软件包时,您应该注意到有所不同. conda activate 更改系统路径,以更改命令外壳程序搜索适当功能的方式.

You should notice a difference when calling external modules / packages. conda activate alters the system path to change how the command shell searches for the appropriate capabilities.

如果提供解释器的完整路径和隔离脚本的完整路径,则Shell无需执行查找,因为它比路径优先.这意味着您可能处于解释器可以看到脚本但看不到依赖项的情况.

If you supply a full path to an interpreter and the full path to an isolated script, then the shell doesn't need to do a lookup as this has priority over the path. This means you could be in a situation where the interpreter can see the script but cannot see dependencies.

如果您遵循 conda activate 流程,并且正确包装了环境,那么外壳将能够跟踪任何其他资源.

If you follow the conda activate process, and the environment is correctly packaged, then the shell will be able to trace any additional resources.

这背后的想法是可移植性.如果管理员在设置系统时非常小心,那么脚本应该具有适当的可见性-即查看环境中的所有内容以及主系统安装中的所有内容.

The idea behind this is portability. If an admin has been careful in setting up a system, then scripts should have the appropriate visibility - i.e. see everything in it's environment plus everything in the main system installation.

可以将对解释器和脚本或程序包位置的所有调用全路径化,但是当您需要将其移至另一台计算机时会发生什么呢?您将需要花费大量时间完全按照以前的方式设置所有内容.另一方面,您可以按照打包过程进行操作,系统路径将为您跟踪所有内容.

It's possible to full-path every call to an interpreter and a script or package location, but then what happens when you need to move it to another machine? You would need to spend a lot of time setting everything up exactly as it was before. On the other hand, you can follow the package process and the system path will trace everything for you.

这篇关于激活anaconda环境和直接运行其python可执行文件有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆