为什么我无法使用“source env/bin/activate”命令激活我的虚拟 Python 环境?

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

How come I can not activate my Virtual Python Environment with 'source env/bin/activate' command?

pythonpylons

提问by

I am trying to activate my Virtual Python Environment to use with Pylons but I think I am executing the commands wrong.

我正在尝试激活我的虚拟 Python 环境以与 Pylons 一起使用,但我认为我执行的命令是错误的。

jem@jem-laptop:~$ source env/bin/activate
bash: env/bin/activate: No such file or directory

What am I doing wrong? How should I do it right?

我究竟做错了什么?我该怎么做才正确?

采纳答案by

I realize I had to do

我意识到我必须这样做

jem@jem-laptop:~$ ls
Desktop    examples.desktop  Public           shortener.rb
Documents  Mac4Lin_v1.0      ruby-1.9.1-p378  Templates
Downloads  Music             rubygems-1.3.7   Videos
Dropbox    Pictures          setcolors.vim    virtualenv.py

And here we see virtualenv.py. From here I just had to

在这里我们看到 virtualenv.py。从这里我只需要

jem@jem-laptop:~$ virtualenv ENV
New python executable in ENV/bin/python
Installing setuptools............done.

And then

进而

jem@jem-laptop:~$ source ENV/bin/activate
(ENV)jem@jem-laptop:~$ deactivate
jem@jem-laptop:~$ 

Solved :)

解决了 :)

回答by 9000

I usually do it this way:

我通常这样做:

$ cd the_project_dir
$ . bin/activate
(the_project)$ _

I need to be in the project directory anyway to go on with the work. Obviously the_project_diris the name of a directory where you have created a virtualenv.

无论如何,我都需要在项目目录中才能继续工作。显然the_project_dir是您在其中创建 virtualenv 的目录的名称。

回答by Ben

I would recommend using virtualenvwrapper. It makes working with virtualenv a lot simpler, especially if you have more than one virtualenv.

我建议使用virtualenvwrapper。它使使用 virtualenv 变得更加简单,尤其是当您有多个 virtualenv 时。

回答by Cyclotron3x3

In 2.7 version I used this command:

在 2.7 版本中我使用了这个命令:

$ cd project_name
$ virtualenv venv --distribute
$ source venv/Scripts/activate
(venv)

回答by Archil Labadze

On FreeBSD I solved this doing following:

在 FreeBSD 上,我通过以下方式解决了这个问题:

# ls mypienv
# mypienv/bin/activate
mypienv/bin/activate: Permission denied.
# chmod +x mypienv/bin/activate
# mypienv/bin/activate
Missing '}'.

And you see that script not working but:

您会看到该脚本不起作用,但是:

# ls mypienv/bin/
activate        activate.fish       easy_install-2.7    pip2.7          python2
activate_this.py    activate.ps1        pip         python          python2.7
activate.csh        easy_install        pip2            python-config       wheel

Finaly:

最后:

# python mypienv/bin/activate_this.py

And it worked! P.S. I am new with python python verions 2.7

它奏效了!PS我是python python verions 2.7的新手

回答by Ka?ss Bouali

Simple fix:

简单的修复:

$ virtualenv env
$ cd env/Scripts/
$ . activate