为什么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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 12:57:21  来源:igfitidea点击:

Why is python saying I have "no module named venv"?

pythonpippython-venv

提问by Amanda

I installed virtual env with sudo pip install virtualenvbut when I run python -m venv flaskI'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

venv is a module introduced in python3

venv是python3中引入的一个模块

venvis New in version 3.3.

venv3.3 版中的新功能。

回答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 venvcommand 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