简体   繁体   English

如何在 anaconda 提示符下运行 powershell 脚本?

[英]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.

相关问题 如何在Windows 10中从常规命令提示符处激活python anaconda并运行脚本 - How do I activate python anaconda and run script from regular command prompt in Windows 10 在 Anaconda 命令提示符中运行 Python 脚本的 Windows 快捷方式 - Windows Shortcut to Run Python Script in Anaconda Command Prompt 如何使用“--”标志运行 Anaconda Powershell 命令 - How to run Anaconda Powershell commands with '--' flags Anaconda Prompt 和 Anaconda Powershell Prompt 有什么区别? - What is the difference between Anaconda Prompt and Anaconda Powershell Prompt? 无法在anaconda提示符下运行tensorboard - unable to run tensorboard on anaconda prompt 如何以管理员权限运行 Anaconda 提示符? - How do I run Anaconda prompt with administrator privileges? 如何安排从anaconda运行的python脚本? - How to schedule python script run from anaconda? How come that conda commands do not show any output in Windows Powershell but in Anaconda PowerShell Prompt? - How come that conda commands do not show any output in Windows Powershell but in Anaconda PowerShell Prompt? 如何使用 anaconda 提示在 anaconda 3 上安装 pgmpy - how to install pgmpy on anaconda 3 using the anaconda prompt Python 脚本在 Anaconda 中运行,但不在 Powershell 中运行 - Python Script Runs in Anaconda but not in Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM