如何在Mac OS Sierra上使用Python3.5安装virtualenvwrapper?

时间:2016-11-22 01:34:31

标签: macos terminal python-3.5 virtualenvwrapper

那么,在这里查看有很多关于如何在Mac上正确安装virtualenvwrapper的问题。我真的尝试了所有这些,但无济于事。我注意到以前的问题不像我的电脑那样配置,所以这里是:

  1. Mac OS Sierra 10.12
  2. Python3.5.2 Mac OS安装程序安装的
  3. python.org
  4. 此安装将Python3.5.2置于此路径中:/Library/Frameworks/Python.framework/Versions/3.5/bin/python3
  5. 我正在运行python3 get-pip.py命令正确安装pip,我认为
  6. sudo pip3 virtualenvwrapper确保所有设置都按照
  7. 进行
  8. 作为the documentation says,使用以下代码编辑~/.bash_profile
    export WORKON_HOME=$HOME/.virtualenvs
    export PROJECT_HOME=$HOME/projects
    source /usr/local/bin/virtualenvwrapper.sh
    
  9. 然后,每当我打开一个新的终端时,我都明白了:

    
    /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.
    
    

    我尝试过其他问题的解决方案,但无济于事:

    1. 在virtualenvwrapper.sh
    2. 上设置VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
    3. 在virtualenvwrapper.sh
    4. 上设置VIRTUALENVWRAPPER_PYTHON="$(command \which python3)"
    5. ln -fs /Library/Frameworks/Python.framework/Versions/3.5/bin/python3 /usr/local/bin/python3
    6. alias python=/usr/local/bin/python3
    7. 好吧,期待任何像我这样配置的人看看我做错了什么。

2 个答案:

答案 0 :(得分:9)

这是相当古老的,但发布这个是因为我从谷歌来到这里,最后想出了正确的道路。

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

你必须确保拥有实际的python可执行文件。只需在Finder中浏览到/ bin并查看其中的内容即可找到。

答案 1 :(得分:2)

嗯,经过大量努力,我决定在macOS Sierra中附带的Python 2.7上安装<?php $strs = array(); while( $rowss = mysql_fetch_array( $result2, MYSQL_ASSOC ) ){ $strs[]=$rowss["ingredient"]; } ?> <script> <?php echo "var strs=JSON.parse( " . json_encode( $strs ) . " );\n"; ?> for( var n in strs ){ var str = strs[ n ]; var str_array = str.split(','); for( var i = 0; i < str_array.length; i++ ) { str_array[i] = str_array[i].replace(/^\s*/, "").replace(/\s*$/, ""); var opt = document.createElement('option'); opt.innerHTML = str_array[i]; opt.value = str_array[i]; sel.appendChild(opt); } } </script> pip

之后,我在virtualenvwrapper上写下了这些行。也许这里有一些多余的东西,但它确实有效。

.bash_profile

之后,我从python.org安装了Python 3.5.2并创建了一个指向它的新环境,一切正常。

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