为什么python说我“没有名为venv的模块”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33181071/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is python saying I have "no module named venv"?
提问by Amanda
I installed virtual env with sudo pip install virtualenv
but when I run python -m venv flask
I'm still getting this: /usr/bin/python: No module named venv
我安装了虚拟环境,sudo pip install virtualenv
但是当我运行时python -m venv flask
我仍然得到这个:/usr/bin/python: No module named venv
Versions, if that's relevant:
版本,如果相关的话:
pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)
Python 2.7.9
what am I missing here?
我在这里错过了什么?
采纳答案by kmad1729
回答by idjaw
Since you are on Python 2, you need to execute using the virtualenv module that you installed.
由于您使用的是 Python 2,您需要使用您安装的 virtualenv 模块执行。
First step, as you originally tried to do, but this time you specify the "virtualenv" module and the name of the virtualenv. In this case flask:
第一步,正如您最初尝试做的那样,但这次您指定了“virtualenv”模块和 virtualenv 的名称。在这种情况下烧瓶:
python -m virtualenv flask
Then you activate your virtualenv like this:
然后你像这样激活你的 virtualenv:
source flask/bin/activate
Then install flask with pip inside the virtualenv
然后在virtualenv中用pip安装flask
pip install flask
If you want to deactivate your virtualenv, simply type:
如果您想停用您的 virtualenv,只需键入:
deactivate
If running on Python 3, the venv
command is built-in and you can simply do:
如果在Python 3上运行,则该venv
命令是内置的,您只需执行以下操作:
python3 -m venv flask
Note, depending on how your Python 3 is installed, your python execution command might differ. You could be running it as python3
, python3.5
, python3.6
.
请注意,根据 Python 3 的安装方式,您的 Python 执行命令可能会有所不同。您可以将其作为python3
, python3.5
,运行python3.6
。