bash 激活 virtualenv 的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37137664/
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
Issue with activating virtualenv
提问by SpanishBoy
I installed python environment by means of commands:
我通过命令安装了python环境:
SYS_INSTALL="apt-get install -y"
PIP_INSTALL="pip install"
# Be sure to install setuptools before pip to properly replace easy_install.
$SYS_INSTALL git
$SYS_INSTALL python-dev
$SYS_INSTALL python-setuptools
$SYS_INSTALL python-pip
$PIP_INSTALL virtualenv
also was able to create new virtual environment:
还能够创建新的虚拟环境:
virtualenv .env
However, after running a command like:
但是,在运行如下命令后:
. .env/bin/activate
I got
我有
-bash: .env/bin/activate: No such file or directory
-bash: .env/bin/activate: 没有那个文件或目录
After reviewing folder .env/bin
I found only one python
file. Whole list of files here:
查看文件夹后,.env/bin
我只找到了一个python
文件。完整的文件列表在这里:
.env/lib:
python2.7
.env/include:
python2.7
.env/bin:
python
What is the issue here?
这里有什么问题?
SOLUTIONadd --always-copy
解决方案添加--always-copy
virtualenv .env --always-copy
virtualenv .env --always-copy
采纳答案by Zach Siegel
The accepted answer is incomplete! The suggested code left out your error, but didn't comment on it.
接受的答案不完整!建议的代码忽略了您的错误,但没有对其发表评论。
The command . .env/bin/activate
would indeed do the same as source
on the file activate
in the folder .env/bin
. In fact, apparently the command "source
" is an alias for the command ".
", and not the other way around. Note that .
here has a space after it, and used differently from the .
discussed below (which makes files and folders hidden).
该命令. .env/bin/activate
确实会与source
文件activate
夹中的文件执行相同的操作.env/bin
。事实上,显然命令“ source
”是命令“ ”的别名.
,而不是相反。请注意,.
此处后面有一个空格,其用法与.
下面讨论的不同(这会隐藏文件和文件夹)。
What I notice is that you are calling your folder .env
, which is not standard practice. Files and folders preceded by .
are made "hidden" by Mac OS X. Standard practice is to call a virtual environment directoryenv
or venv
, and to call the virtual environment specification file.env
.
我注意到您正在调用您的文件夹.env
,这不是标准做法。前面的文件和文件夹.
被 Mac OS X“隐藏”。标准做法是调用虚拟环境目录env
或venv
,并调用虚拟环境规范文件.env
。
So, if your spec file is called .env
and your virtual environment directory is called env
, you can run either
因此,如果您的规范文件被调用.env
并且您的虚拟环境目录被调用env
,您可以运行
source env/bin/activate
or
. env/bin/activate
.
source env/bin/activate
或
. env/bin/activate
。
回答by Alex
For me it works when I do these steps:
对我来说,当我执行以下步骤时它有效:
Go to the directory/folder that you want
run
virtualenv .env
then run
source .env/bin/activate
转到您想要的目录/文件夹
跑
virtualenv .env
然后运行
source .env/bin/activate
回答by shivsn
you forgot to include source
before activating command issource env/bin/activate
您source
在激活命令之前忘记包含source env/bin/activate
this question is similar to your's
virtualenv is not compatible with this system or executablewhere it creates virtualenv but,python
file instead of activate
in bin
这个问题类似于你的
virtualenv 与这个系统或可执行文件不兼容,它创建了 virtualenv 但是,python
文件而不是activate
bin
回答by Asmath
I was facing this same issue. I uninstalled the virtualenv in Ubuntu and then I installed it again. After this nonsense, it works and now I am able to activate my virtualenv through -$source py3/bin/activate
.
我面临着同样的问题。我在 Ubuntu 中卸载了 virtualenv,然后再次安装了它。在这些废话之后,它起作用了,现在我可以通过-$source py3/bin/activate
.
回答by Abhishek Pratap Singh
After going to your virtual environment folder .\Scripts\activate
.
转到您的虚拟环境文件夹后.\Scripts\activate
。