bash 无法找到或创建新的 virtualenv

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39814281/
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-09-18 15:14:49  来源:igfitidea点击:

Can't Find or create a new virtualenv

pythonbashvirtualenvpython-venv

提问by Malik A. Rumi

I just got Python 3.5.2 and wanted to create a virtualenv.

我刚刚获得 Python 3.5.2 并想创建一个 virtualenv。

I have done this before. Right now, I have a virtualenv on a Python2.7 project that I can still open with source bin/activate.

我以前做过这个。现在,我在 Python2.7 项目上有一个 virtualenv,我仍然可以使用 source bin/activate 打开它。

But try as I might, from /home, or from /path/to/virtualenv, or /path/to/virtualenv-$, with or without sudo and python prepended on the command line, I only get one response: no such file or directory.

但是尽我所能,从 /home 或 /path/to/virtualenv 或 /path/to/virtualenv-$,无论是否在命令行中添加 sudo 和 python,我只得到一个响应:没有这样的文件或目录。

This was with the -p flag so it would use 3.5.2, because 2.7.12 is still my default. If it is broken, why does the virtualenv I created for 2.7 still activate?

这是带有 -p 标志的,因此它将使用 3.5.2,因为 2.7.12 仍然是我的默认值。如果坏了,为什么我为 2.7 创建的 virtualenv 仍然激活?

Then I tried pyvenv and venv (which I've never used before) from the 3.5.2 interpreter:

然后我从 3.5.2 解释器中尝试了 pyvenv 和 venv(我以前从未使用过):

>>> pyvenv /home/malikarumi/Projects/aishah
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pyvenv' is not defined
>>> venv /home/malikarumi/Projects/aishah
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'venv' is not defined

and from bash:

来自 bash:

malikarumi@Tetuoan2:~$ malikarumi@Tetuoan2:/usr/local/bin$ python3.5    pyvenv ~/Projects/aishah
bash: malikarumi@Tetuoan2:/usr/local/bin$: No such file or directory
malikarumi@Tetuoan2:~$ malikarumi@Tetuoan2:/usr/local/bin$ python3.5 venv ~/Projects/aishah
bash: malikarumi@Tetuoan2:/usr/local/bin$: No such file or directory

What am I doing wrong?

我究竟做错了什么?

回答by ThoWe

Using virtualenv

使用 virtualenv

First of all you should verify that virtualenv is really installed for Python 3.5:

首先,您应该验证是否真的为 Python 3.5 安装了 virtualenv:

python3.5 -m pip list

python3.5 -m pip list

If it's not then install it either with the package manager of your distribution or by running python3.5 -m pip install virtualenv.

如果不是,则使用发行版的包管理器或运行python3.5 -m pip install virtualenv.

Then you can run python3.5 -m virtualenv <newvenv>and it should create a new virtualenv using Python 3.5 for you.

然后你可以运行python3.5 -m virtualenv <newvenv>,它应该使用 Python 3.5 为你创建一个新的 virtualenv。

Using venv that is already part of the standard library in Python 3.5

使用 venv 已经是 Python 3.5 标准库的一部分

Simply running python3.5 -m venv <newvenv>should do the job.

只需跑步就python3.5 -m venv <newvenv>可以完成这项工作。