简体   繁体   English

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

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

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?我该怎么做才正确?

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.在这里我们看到 virtualenv.py。 From here I just had to从这里我只需要

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 :)解决了:)

In 2.7 version I used this command:在 2.7 版本中我使用了这个命令:

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

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_dir is the name of a directory where you have created a virtualenv.显然the_project_dir是您在其中创建 virtualenv 的目录的名称。

I would recommend using virtualenvwrapper .我建议使用virtualenvwrapper It makes working with virtualenv a lot simpler, especially if you have more than one virtualenv.它使使用 virtualenv 变得更加简单,尤其是当您有多个 virtualenv 时。

Simple fix:简单的修复:

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

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!它奏效了! PS I am new with python python verions 2.7 PS我是python python verions 2.7的新手

env/Scripts/activate为我工作。

对于 Windows,以下对我有用:

C:\\.virtualenvs\\env\\Scripts>activate.bat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM