[英]How to run powershell script in anaconda prompt?
I am using a windows pc with no admin rights.我正在使用没有管理员权限的 windows 电脑。 Python is installed but only works in anaconda prompt and not in normal cmd prompt because it is not added to path.
Python 已安装,但仅适用于 anaconda 提示,而不适用于正常 cmd 提示,因为它未添加到路径中。 Since I have no admin rights I cannot add it.
由于我没有管理员权限,我无法添加它。
I have a fairly simple powershell script that runs a bunch of python scripts:我有一个相当简单的 powershell 脚本,它运行一堆 python 脚本:
cd mydir
python script1
"script 1 done"
python script2
"finished"
EDIT: Right now, I open anaconda prompt and manually paste the script in and hit enter.编辑:现在,我打开 anaconda 提示符并手动粘贴脚本并按回车键。 Everything works perfect.
一切都很完美。 Is there a way to do that in powershell, ie tell powershell to open anaconda prompt (not standard cmd) and paste the script to it.
有没有办法在 powershell 中做到这一点,即告诉 powershell 打开 anaconda 提示符(非标准 cmd)并将脚本粘贴到它。
You can add it to your path yourself, either in powershell:您可以自己将其添加到您的路径中,在 powershell 中:
$env:path += ';C:\ProgramData\Anaconda3'
cd mydir
python script1
"script 1 done"
python script2
"finished"
Or in your windows profile.或在您的 windows 配置文件中。 Either in the Control Panel, or see the "User" form of this: Setting Windows PowerShell environment variables
在控制面板中,或查看“用户”表单: 设置 Windows PowerShell 环境变量
The shortcut to Anaconda powershell does a lot of things. Anaconda powershell 的快捷方式做了很多事情。 Somehow you have to reproduce this if you don't want to use it.
如果你不想使用它,你必须以某种方式重现它。 I'm not an Anaconda user.
我不是 Anaconda 用户。
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\ProgramData\Anaconda3' "
Maybe put this at the top of your script.也许把它放在你脚本的顶部。 It would modify the path as well.
它也会修改路径。
C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1
conda activate C:\ProgramData\Anaconda3
Adding.all three!添加。所有三个! paths fixed the problem for me.
路径为我解决了这个问题。
$env:path += ';C:\ProgramData\Anaconda3\'
$env:path += ';C:\ProgramData\Anaconda3\Scripts\'
$env:path += ';C:\ProgramData\Anaconda3\Library\bin'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.