繁体   English   中英

如何使用PowerShell激活virtualenv?

[英]How to activate virtualenv using PowerShell?

我制作了名为bitcoin_notifications.py的virtualenv,我将激活它,但是:

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'. The module 'bitcoin_notifications' could not be loaded. For more information, run 'Import-Module bitcoin_notifications'. 在行:1 char:1 + bitcoin_notifications \\ activate.ps1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo :ObjectNotFound:(bitcoin_notifications \\ activate.ps1:String)[],CommandNotFoundException + FullyQualifiedErrorId:CouldNotAutoLoadModule

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

一旦我运行它,

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

Import-Module:未加载指定的模块“bitcoin_notifications”,因为在任何模块目录中都找不到有效的模块文件。 At line:1 char:1 + Import-Module bitcoin_notifications + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (bitcoin_notifications:String) [Import-Module], FileNotFoundException + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand```

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

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

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

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

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

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

我使用Windows 10时遇到了类似的问题。

所以,最初安装Python 3.7(添加到Path)并确保pip正常工作

PS C:\foldername> pip

然后,运行以下命令以安装virtualenv

PS C:\foldername> pip install --upgrade setuptools
PS C:\foldername> pip install ez_setup
PS C:\foldername> pip install virtualenv

创建了一个virtualenvs文件夹并进入它

PS C:\foldername> mkdir virtualenvs
PS C:\foldername> cd virtualenvs

然后,创建虚拟环境分子

PS C:\foldername\virtualenvs> virtualenv molecoder
PS C:\foldername\virtualenvs> Set-ExecutionPolicy Unrestricted -Force

并试图激活它

PS C:\foldername\virtualenvs> molecoder\Scripts\acivate

并得到以下消息

moleco \\ Scripts \\ acivate:无法加载模块“molecoder”。 有关更多信息,请运行“Import-Module molecule”。 在行:1 char:1 + moleculeoder \\ Scripts \\ acivate + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:ObjectNotFound :( moleculeoder \\ Scripts \\ acivate:String)[],CommandNotFoundException + FullyQualifiedErrorId:CouldNotAutoLoadModule

在我的情况下是因为我写了acivate而不是激活 ,所以以下修改工作

PS C:\foldername\virtualenvs> molecoder\Scripts\activate

在您的情况下,您尝试激活但激活是在envname / Scripts内部,您将到达错误的位置。

要解决它,你只需要运行

PS C:\Users\piotr> bitcoin_notifications\Scripts\activate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM