質問

I'm trying to get to grips with Python virtual environments and have followed a few excellent tutorials such as simononsoftware and IAmZed which were recommended in an answer to another SO question here

However I am having some problems with virtualenvwrapper. I am reading the docs here

I believe I have installed virtualenvwrapper correctly. When I type

localhost:workspace brendan$ which virtualenvwrapper.sh 

I receive the below. Note: This is outside my virtual environment.

/usr/local/bin/virtualenvwrapper.sh

However when I enter my virtual environment via

localhost:workspace brendan$ source virt_env/Credibility/bin/activate

and type

(Credibility)localhost:workspace brendan$ lssitepackages

I receive

-bash: lssitepackages: command not found

I have also installed virtualenvwrapper inside my Credibility virtualenv but the command still does not work.

This is my yolk -l output from within the Credibility Virtualenv

(Credibility)localhost:workspace brendan$ yolk -l
Django          - 1.5.1        - active 
Python          - 2.7.1        - active development (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload)
SQLAlchemy      - 0.8.2        - active 
distribute      - 0.7.3        - active 
nose            - 1.3.0        - active 
pip             - 1.4          - active 
setuptools      - 0.9.7        - active 
stevedore       - 0.10         - active 
virtualenv-clone - 0.2.4        - active 
virtualenv      - 1.10.1       - active 
virtualenvwrapper - 4.1.1        - active 
wsgiref         - 0.1.2        - active development (/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7)
yolk            - 0.4.3        - active 
(Credibility)localhost:workspace brendan$ 

My suspicion where I might be going wrong. In the docs it says to

First, some initialization steps. Most of this only needs to be done one time. You will want to add the command to source /usr/local/bin/virtualenvwrapper.sh to your shell startup file, changing the path to virtualenvwrapper.sh depending on where it was installed by pip.

I was not really sure how to do this so I followed the instructions in another SO answer here

localhost:documents brendan$ cd workspace/
localhost:workspace brendan$ pwd
/Users/brendan/documents/workspace
localhost:workspace brendan$ cat >> ~/.profile
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Users/brendan/documents/workspace
source /usr/local/bin/virtualenvwrapper.sh
localhost:workspace brendan$ source ~/.bash_profile
localhost:workspace brendan$ 

I thought this would have fixed it, as you can see I reloaded my Terminal window, I also restarted it. However unlike installing a package, this gave me no feedback as I completed each of the steps and I think it might be causing the problem.

Can anyone see an issue here or is there another problem I am not seeing?

Thanks for the help

Setup: Mac OSX 10.7.5

役に立ちましたか?

解決

First, you should instal virtualenvwrapper outside of your virtual environment, not inside it. Then adjust your profile accordingly:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/documents/workspace
source /usr/local/bin/virtualenvwrapper.sh

You have the wrong path for PROJECT_HOME

Next, as you have done source the file.

Finally:

$ mkvirtualenv foo
...
(foo)$ lsvirtualenv

Doing so with the mkvirtualenv command ensures that the correct files are executed, which will add the commands with the right paths in your virtual environment. Next time you want to work on a virtual envronment, you should use the workon command, as in:

 $ workon foo

This will make sure the paths are set up correctly along with the virtualenv wrapper specific commands.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top