How to definitely install virtualenvwrapper with P

2019-04-08 06:24发布

问题:

Well, looking around here there are tons of questions about how to correctly installing virtualenvwrapper on Mac. I really tried all of them but for no avail. I've noticed the previous questions don't have the configuration like my computer, so here it is:

  1. Mac OS Sierra 10.12
  2. Python3.5.2 installed from python.org installer for Mac OS
  3. This installation puts Python3.5.2 in this path: /Library/Frameworks/Python.framework/Versions/3.5/bin/python3
  4. I've run python3 get-pip.pycommand to install pip correctly, as I think
  5. sudo pip3 virtualenvwrapper to be sure all settings will be done as they should
  6. As the documentation says, edited ~/.bash_profile with the code below:
    export WORKON_HOME=$HOME/.virtualenvs
    export PROJECT_HOME=$HOME/projects
    source /usr/local/bin/virtualenvwrapper.sh
    

Then, whenever I open a new fresh Terminal, I got this:


/usr/bin/python: No module named virtualenvwrapper virtualenvwrapper.sh:
There was a problem running the initialization hooks. 

If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for 
 VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is set properly.

I've tried the fixes from others questions, to no avail:

  1. set VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3 on virtualenvwrapper.sh
  2. set VIRTUALENVWRAPPER_PYTHON="$(command \which python3)" on virtualenvwrapper.sh
  3. ln -fs /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 /usr/local/bin/python3
  4. alias python=/usr/local/bin/python3

Well, looking forward to anyone with a configuration like mine to see what I'm doing wrong.

回答1:

This is pretty old, but posting this because I came here from google and finally figured out the right paths.

export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
export PROJECT_HOME=$HOME/Devel
source /Library/Frameworks/Python.framework/Versions/3.6/bin/virtualenvwrapper.sh

You have to make sure to have the actual python executable. This can be found by just simply browsing in Finder through to /bin and seeing what is there.



回答2:

Well, after a lot of effort, I've decided to install pip and virtualenvwrapper on Python 2.7 shipped in macOS Sierra.

After that, I wrote the lines below on .bash_profile. Maybe there's something redundant here but, it works.

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Documents/Projects/
ln -fs /Users/myusername/Library/Python/2.7/bin/virtualenvwrapper.sh /usr/local/bin/virtualenvwrapper.sh
ln -fs /Users/myusername/Library/Python/2.7/bin/virtualenv /usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

After that, I've installed Python 3.5.2 from python.org and created a new enviroment pointing to it and everything is working just fine.

mkvirtualenv --python=python3.5 env_name