问题描述
我刚刚获得 Python 3.5.2 并想创建一个 virtualenv.
我以前做过这个.现在,我在 Python2.7 项目上有一个 virtualenv,我仍然可以使用 source bin/activate 打开它.
但是尽我所能,从/home 或/path/to/virtualenv 或/path/to/virtualenv-$,无论是否在命令行中添加 sudo 和 python,我只能得到一个响应:没有这样的文件或目录.
这是带有 -p 标志的,因此它将使用 3.5.2,因为 2.7.12 仍然是我的默认值.如果坏了,为什么我为2.7创建的virtualenv还激活?
然后我从 3.5.2 解释器中尝试了 pyvenv 和 venv(我以前从未使用过):
>>>pyvenv/home/malikarumi/项目/艾莎回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中NameError: 名称 'pyvenv' 未定义>>>venv/home/malikarumi/Projects/aishah回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中NameError: 名称 'venv' 未定义来自 bash:
malikarumi@Tetuoan2:~$ malikarumi@Tetuoan2:/usr/local/bin$ python3.5 pyvenv ~/Projects/aishahbash: malikarumi@Tetuoan2:/usr/local/bin$: 没有那个文件或目录malikarumi@Tetuoan2:~$ malikarumi@Tetuoan2:/usr/local/bin$ python3.5 venv ~/Projects/aishahbash: malikarumi@Tetuoan2:/usr/local/bin$: 没有那个文件或目录
我做错了什么?
使用 virtualenv
首先,您应该验证是否真的为 Python 3.5 安装了 virtualenv:
python3.5 -m pip list
如果不是,则使用发行版的包管理器或运行 python3.5 -m pip install virtualenv
安装它.
然后您可以运行 python3.5 -m virtualenv <newvenv>
它应该会为您创建一个使用 Python 3.5 的新 virtualenv.
使用已经是 Python 3.5 标准库一部分的 venv
只需运行 python3.5 -m venv
就可以完成这项工作.
I just got Python 3.5.2 and wanted to create a 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.
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.
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?
Then I tried pyvenv and venv (which I've never used before) from the 3.5.2 interpreter:
>>> 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:
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?
Using virtualenv
First of all you should verify that virtualenv is really installed for Python 3.5:
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
.
Then you can run python3.5 -m virtualenv <newvenv>
and it should create a new virtualenv using Python 3.5 for you.
Using venv that is already part of the standard library in Python 3.5
Simply running python3.5 -m venv <newvenv>
should do the job.
这篇关于无法找到或创建新的 virtualenv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!