无法在Windows 10中激活Python venv [英] Can't activate Python venv in Windows 10

查看:424
本文介绍了无法在Windows 10中激活Python venv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从命令提示符下使用 python -m venv myenv 创建了一个虚拟环境,但是我不知道如何激活它。我尝试从命令提示符处执行 activate.bat ,但它没有激活。

I created a virtual environment with python -m venv myenv from the command prompt, but I don't know how to activate it. I tried executing activate.bat from the command prompt but it does not activate.

换句话说,我不知道没有看到当前路径更改为(myenv)C:\路径名... 表示myenv已被激活。当我执行 activate.bat 时,虚拟电话未激活。

In other words, I don't see the current path changed to (myenv) C:\Pathname... to indicate that myenv has been activated. When I execute activate.bat the venv is not activated.

推荐答案

这个线程很旧,但是今天我遇到了同样的问题,并找到了可行的答案。我一直在使用python 3.6 venv几个月,没有任何问题,但是今天我遇到了一条新的错误消息:

This thread it old but I had the same problem today and found a working answer for it. I've been using python 3.6 venv for a few months now without issues but today I ran across a new error message:

C:\test>python -m venv vm
Error: Command '['C:\\test\\vm\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

我搜寻了Stack和其他资源来寻找答案,但是没有找到Windows 10的特定内容。(AskUbunto有一个Linux特定的解决方案)。我确实发现面包屑散布在整个InterWeb上,并将它们拼凑在一起。

I scoured Stack and other resources for an answer but didn't find anything specific to Windows 10. (AskUbunto had a solution that was specific to Linux). I did find breadcrumbs spread out across the InterWebs and pieced this together.

您需要以下python脚本: https://bootstrap.pypa.io/get-pip.py

You need this python script: https://bootstrap.pypa.io/get-pip.py


  1. 照常安装虚拟环境,但没有pip:

  1. Install your virtual environment as usual but without pip:

python -m venv virtual --without-pip

python -m venv virtual --without-pip

此方法将创建所有必需的文件,包括激活蝙蝠文件。

This method will create all of the necessary files including the activate bat files.


  1. 将get-pip.py文件复制到virtual\Scripts子目录

  1. Copy the get-pip.py file into the virtual\Scripts subdirectory

cd进入Scripts子目录并激活 python注意:cmd行应命名从中激活python的目录:

cd into the Scripts subdirectory and "activate" python Note: the cmd line should name the directory from which python was activated:

(虚拟)C:\ \test\virtual\Scripts>

(virtual) C:\test\virtual\Scripts>

(如果显示(root),则表示已激活您的核心安装)

(if it says (root), it's activated your core installation)


  1. 现在执行脚本

  1. now execute the script

C:\test\virtual\Scripts> python get-pip.py

C:\test\virtual\Scripts>python get-pip.py

一次运行,我输入:

(virtual) C:\test\virtual\Scripts>pip freeze

生成冻结列表并验证正确的安装。它应该什么也不返回,没有错误消息,没有冻结列表。

to generate a freeze list and verify proper installation. It should return nothing, no error msg, no freeze list.


  1. 然后我安装了烧瓶,尝试了pip冻结并记下返回仅适用于flask和相关文件:




(虚拟)C:\test\ virtual\脚本> pip冻结

click == 6.7

烧瓶== 0.12.2

itsdangerous == 0.24

Jinja2 == 2.9.6

MarkupSafe == 1.0

Werkzeug == 0.12.2

(virtual) C:\test\virtual\Scripts>pip freeze
click==6.7
Flask==0.12.2
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
Werkzeug==0.12.2

这篇关于无法在Windows 10中激活Python venv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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