如何使用 PowerShell 激活 virtualenv? [英] How to activate virtualenv using PowerShell?

查看:45
本文介绍了如何使用 PowerShell 激活 virtualenv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了名为 bitcoin_notifications.py 的 virtualenv,我准备激活它,但是:

PS C:\Users\piotr>bitcoin_notifications\activate.ps1

<块引用>

bitcoin_notifications\activate.ps1 : 模块无法加载bitcoin_notifications".有关更多信息,请运行'Import-Module bitcoin_notifications'. 在 line:1 char:1+ bitcoin_notifications\activate.ps1+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : ObjectNotFound: (bitcoin_notifications\activate.ps1:String) [],命令未找到异常+ FullQualifiedErrorId:CouldNotAutoLoadModule

在我们读取模块之前共享的结果中,无法加载模块,如果需要更多信息来运行另一个特定命令.

一旦我运行它,

PS C:\Users\piotr>```导入模块 bitcoin_notifications

<块引用>

Import-Module : 指定的模块bitcoin_notifications"不是加载,因为在任何模块中都找不到有效的模块文件目录.<代码>在行:1 字符:1+ 导入模块 bitcoin_notifications+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : ResourceUnavailable: (bitcoin_notifications:String) [Import-Module], FileNotFoundException+ FullQualifiedErrorId :Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand```

我们可以理解该目录中没有模块.我只想激活virtualenv,我该怎么做?

解决方案

我不熟悉 PowerShell,但 activate.ps1 的第一行似乎提到了解决方案:

# 此文件必须来自 PoSh;你不能运行它# 直接地.做这个: ../activate.ps1

因此,以下应该有效(您评论中的第 4 步和第 5 步 - 请注意,第 5 步缺少点!):

virtualenv bitcoin_notifications..\bitcoin_notifications\Scripts\activate.ps1

注意:您的问题提到了venv",但实际上是关于virtualenv"的.请注意,这是两个相似但不同的工具.当您使用正确的术语时,人们会更容易找到并回答您的问题.此外,在您的帖子中包含 shell 命令时,请使用您使用过的完全相同的命令,以便其他人可以重现相同的步骤(看起来情况并非如此,因为第 5 步缺少脚本"部分).谢谢!

I made virtualenv called bitcoin_notifications.py and I'm going to activate it but:

PS C:\Users\piotr> bitcoin_notifications\activate.ps1

bitcoin_notifications\activate.ps1 : The module 'bitcoin_notifications' could not be loaded. For more information, run 'Import-Module bitcoin_notifications'. At line:1 char:1 + bitcoin_notifications\activate.ps1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (bitcoin_notifications\activate.ps1:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoLoadModule

In the result shared before we read the module could not be loaded and if one wants more info to run another specific command.

Once i run it,

PS C:\Users\piotr> ```Import-Module bitcoin_notifications

Import-Module : The specified module 'bitcoin_notifications' was not loaded because no valid module file was found in any module directory.At line:1 char:1 + Import-Module bitcoin_notifications + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (bitcoin_notifications:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId :Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand```

we can understand there's no module in that directory. I just want to activate the virtualenv, how can i do it?

解决方案

I'm not familiar with PowerShell, but the first lines from activate.ps1 seem to mention the solution:

# This file must be dot sourced from PoSh; you cannot run it
# directly. Do this: . ./activate.ps1

So, the following should work (step 4 and 5 from your comment - note that step 5 was missing the dot!):

virtualenv bitcoin_notifications
. .\bitcoin_notifications\Scripts\activate.ps1

NB: Your question mentions 'venv' but actually is about 'virtualenv'. Note that these are two similar but different tools. When you use the correct terms, it is easier for people to find and answer your question. Also, when including shell commands in your posts, please use the exact same commands that you've used so other people can reproduce the same steps (it looks like this is not the case, since step 5 is missing the "scripts" part). Thanks!

这篇关于如何使用 PowerShell 激活 virtualenv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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