programing

virtualenv를 활성화하는 방법?

new-time 2020. 5. 10. 12:29
반응형

virtualenv를 활성화하는 방법?


나는 수색을 겪고 성공하지 못하고 다양한 대안을 시도했으며 지금 며칠을 보냈다.Python 2.5.2를 사용하여 Red Hat Linux에서 실행 중 가장 최신 Virtualenv를 사용하기 시작했지만이를 활성화 할 수 없었습니다. 이전 버전이 필요하다는 것을 알았으므로 Python 2.6에서 작동하는 Virtualenv 1.6.4를 사용했습니다.

가상 환경을 설치하는 것 같습니다.

[necrailk@server6 ~]$ python virtualenv-1.6.4/virtualenv.py virtual
New python executable in virtual/bin/python
Installing setuptools............done.
Installing pip...............done.

환경은 좋아 보인다

[necrailk@server6 ~]$ cd virtual
[necrailk@server6 ~/virtual]$ dir
bin  include  lib

활성화하려고

[necrailk@server6 ~/virtual]$ . bin/activate
/bin/.: Permission denied.

확인 된 chmod

[necrailk@server6 ~/virtual]$ cd bin
[necrailk@server6 bin]$ ls -l
total 3160
-rw-r--r--    1 necrailk biz12        2130 Jan 30 11:38 activate
-rw-r--r--    1 necrailk biz12        1050 Jan 30 11:38 activate.csh
-rw-r--r--    1 necrailk biz12        2869 Jan 30 11:38 activate.fish
-rw-r--r-

문제, 그래서 나는 그것을 바꿨다

[necrailk@server6 bin]$ ls -l
total 3160
-rwxr--r--    1 necrailk biz12        2130 Jan 30 11:38 activate
-rw-r--r--    1 necrailk biz12        1050 Jan 30 11:38 activate.csh
-rw-r--r--    1 necrailk biz12        2869 Jan 30 11:38 activate.fish
-rw-r--r--    1 necrailk biz12        1005 Jan 30 11:38 activate_this.py
-rwxr-xr-x    1 necrailk biz

activate다시 시도 하십시오

[necrailk@server6 ~/virtual]$ . bin/activate
/bin/.: Permission denied.

여전히 기쁨은 없습니다 ...


폴더를 만들고 폴더에 넣은 후의 워크 플로는 다음과 같습니다

cd

.

$ virtualenv venv --distribute
New python executable in venv/bin/python
Installing distribute.........done.
Installing pip................done.
$ source venv/bin/activate
(venv)$ python

 

source bin/activate

source가 실행 파일 이름 인 곳을 잊어 버렸습니다 . 매뉴얼이 "환경 폴더의 루트에서 이것을 실행한다"고 말하는 것은 쉬운 일이다.를 통해

activate

실행 파일 을 만들 필요가 없습니다

chmod

.


넌 할 수있어

source ./python_env/bin/activate

아니면 그냥 디렉토리로 이동

cd /python_env/bin/

그리고

source ./activate

행운을 빕니다.


CD를 환경 경로로 이동하고 bin 폴더로 이동하십시오. 이 시점에서 ls 명령을 사용하면 "activate"파일이 표시됩니다.이제 입력

source activate

프로젝트 디렉토리로 이동하십시오. 내 경우에는

microblog

플라스크 프로젝트 디렉토리이고 아래에

microblog

디렉토리가 있어야

app

venv

폴더. 그런 다음 아래 명령을 실행하십시오. 이것은 우분투에서 나를 위해 일한 것입니다.

source venv/bin/activate

enter image description here


문제는

/bin/.

명령입니다. 이후 정말 이상합니다. (항상

.

이상한 별명이나 함수가 아니라면 어떻게 가능한지 알지 못합니다.) 쉘에

. 내장source

이없는 것도 드문 일입니다 .

One quick fix would be to just run the virtualenv in a different shell. (An obvious second advantage being that instead of having to deactivate you can just exit.)

/bin/bash --rcfile bin/activate

If your shell supports it, you may also have the nonstandard source command, which should do the same thing as ., but may not exist. (All said, you should try to figure out why your environment is strange or it will cause you pain again in the future.)

By the way, you didn't need to chmod +x those files. Files only need to be executable if you want to execute them directly. In this case you're trying to launch them from ., so they don't need it.


$ mkdir <YOURPROJECT> Create a new project

$ cd <YOURPROJECT> Change directory to that project

$ virtualenv <NEWVIRTUALENV> Creating new virtualenv

$ source <NEWVIRTUALENV>/bin/activate Activating that new virtualenv


instead of ./activate

use source activate

See this screenshot


For Windows You can perform as:

TO create the virtual env as: virtualenv envName –python=python.exe (if not create environment variable)

To activate the virtual env : > \path\to\envName\Scripts\activate

To deactivate the virtual env : > \path\to\env\Scripts\deactivate

It fine works on the new python version .


I would recommend virtualenvwrapper as well. It works wonders for me and how I always have problems with activating. http://virtualenvwrapper.readthedocs.org/en/latest/


Create your own Python virtual environment called <Your Env _name >:. I have given it VE.

git clone https://github.com/pypa/virtualenv.git
python virtualenv.py VE

To activate your new virtual environment, run (notice it's not ./ here):

. VE/bin/activate

Sample output (note prompt changed):

(VE)c34299@a200dblr$

Once your virtual environment is set, you can remove the Virtualenv repo.


I had trouble getting running source /bin/activate then I realized I was using tcsh as my terminal shell instead of bash. once I switched I was able to activate venv.


On Mac, change shell to BASH (keep note that virtual env works only in bash shell )

[user@host tools]$. venv/bin/activate 

.: Command not found.

[user@host tools]$source venv/bin/activate

Badly placed ()'s.

[user@host tools]$bash

bash-3.2$ source venv/bin/activate

(venv) bash-3.2$ 

Bingo , it worked. See prompt changed.

On Ubuntu:

user@local_host:~/tools$ source toolsenv/bin/activate

(toolsenv) user@local_host~/tools$ 

Note : prompt changed


source virtualen_name/bin/activate

code


Probably a little late to post my answer here but still I'll post, it might benefit someone though,

I had faced the same problem,

The main reason being that I created the virtualenv as a "root" user But later was trying to activate it using another user.

chmod won't work as you're not the owner of the file, hence the alternative is to use chown (to change the ownership)

For e.g. :

If you have your virtualenv created at /home/abc/ENV

Then CD to /home/abc

and run the command : chown -Rv [user-to-whom-you want-change-ownership] [folder/filename whose ownership needs to be changed]

In this example the commands would be : chown -Rv abc ENV

After the ownership is successfully changed you can simply run source /ENV/bin/./activate and your should be able to activate the virtualenv correctly.


1- open powershell and navigate to your application folder 2- enter your virtualenv folder ex : cd .\venv\Scripts\ 3- active virtualenv by type .\activate

참고URL : https://stackoverflow.com/questions/14604699/how-to-activate-virtualenv

반응형