Python 小牛升级后 virtualenvwrapper 的终端问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19549824/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:01:54  来源:igfitidea点击:

Terminal issue with virtualenvwrapper after Mavericks Upgrade

pythonterminalvirtualenvwrapperosx-mavericks

提问by Ryan Allen

After upgrading to OSX Mavericks, I am getting this message in the terminal:

升级到 OSX Mavericks 后,我在终端中收到此消息:

/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 virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.

采纳答案by Beau

Try reinstalling pip and then reinstalling virtualenvwrapper (I had to go through these steps after upgrading to Mavericks):

尝试重新安装 pip,然后重新安装 virtualenvwrapper(升级到 Mavericks 后我必须完成这些步骤):

$ sudo easy_install pip
$ sudo pip install --upgrade virtualenvwrapper

回答by metakermit

I wouldn't recommend running pip with sudo. Thiswas my solution for the same problem (after upgrading to Mavericks).

我不建议使用 sudo 运行 pip。是我对同一问题的解决方案(升级到小牛队后)。

In essence, uninstall any virtualenv and brewed Python you had before (use which <command>to check that you removed everything except the system Python in /usr/bin/python) and cleanly install them once again:

本质上,卸载您之前拥有的任何 virtualenv 和 brewed Python(用于which <command>检查您是否删除了除系统 Python 中的所有内容/usr/bin/python)并再次干净地安装它们:

brew install python --with-brewed-openssl
# Open a new terminal tab now (to access /usr/local/bin/python)
pip install virtualenv
pip install virtualenvwrapper

回答by Josh Antweiler

Re-arrange the export order so that the pythonpath is placed before the virtualenvcommands in your .bash_profilefile.

重新安排导出顺序,以便将python路径放置在文件中的virtualenv命令之前.bash_profile

# python path
export PATH=/usr/local/bin:$PATH

# needed for virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

回答by syodage

pip install --upgrade virtualenvwrapperwill fix the issue but never used sudo pipthis will change system-wide. If pip throws permission errors without sudothen you should fix those and then try only with pip install <--upgrade> $(package).

pip install --upgrade virtualenvwrapper将解决问题但从未使用过sudo pip这将在系统范围内改变。如果 pip 在没有的情况下抛出权限错误,sudo那么您应该修复这些错误,然后仅尝试使用pip install <--upgrade> $(package).

I rather suggest install homebrewand then install pipusing brew install pipwhich will install latest stable version of pip for you.

我宁愿建议先安装homebrew,然后pip使用brew install pip它安装,这将为您安装最新的稳定版本的 pip。

  1. Install homebrewand then run brew doctor. If there are any warnings fix those(actually brew will tell you how to fixed those).

  2. You may need to remove system-wide python comes with Mac and use brewto install required versions. Use thisto remove system-wide python

  3. Use brew install pythonor/and brew install python3to install required python version/s.
  4. Finaly run pip install --upgrade virtualenvwrapper

  5. Now on never use sudo piponly use pip.

  1. 安装自制软件,然后运行brew doctor. 如果有任何警告修复这些(实际上 brew 会告诉你如何修复这些)。

  2. 您可能需要删除 Mac 附带的系统范围的 python 并用于brew安装所需的版本。使用来删除系统范围的python

  3. 使用brew install python或/和brew install python3安装所需的python版本/s。
  4. 最后运行 pip install --upgrade virtualenvwrapper

  5. 现在从不使用sudo pip只使用pip

回答by Tuan Pham

Try edit .bash_profile file

尝试编辑 .bash_profile 文件

# Home brew
export PATH=/usr/local/bin:$PATH

# virtualenvwrapper 
export WORKON_HOME=$HOME/.virtualenvs
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

回答by neosergio

I had the same problem with MacOS High Sierra. I was able to fix it with these lines in my .bash_profile file:

我在 MacOS High Sierra 上遇到了同样的问题。我能够在我的 .bash_profile 文件中使用这些行修复它:

export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Code
export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python2
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
source /usr/local/bin/virtualenvwrapper.sh

回答by Nilisha Maheshwari

Running these two commands helped me get rid of it (had done a software update on macOS High Sierra)

运行这两个命令帮助我摆脱了它(在 macOS High Sierra 上做了软件更新)

$ sudo easy_install pip

$ sudo pip install --upgrade virtualenvwrapper

回答by PRIYANSHU SHARMA

You just need to configure the path properly. Run the following commands in the terminal:

您只需要正确配置路径。在终端中运行以下命令:

  1. which python
  1. which python

Output -

输出 -

/usr/bin/python
  1. which virtualenvwrapper.sh
  1. which virtualenvwrapper.sh

Output -

输出 -

/usr/local/bin/virtualenvwrapper.sh
  1. echo $VIRTUALENVWRAPPER_PYTHON

    /usr/local/bin/python

  1. echo $VIRTUALENVWRAPPER_PYTHON

    /usr/local/bin/python

So as you can see that the variable $VIRTUALENVWRAPPER_PYTHONis pointing towards the wrong python path. So we need to reset the path of variable $VIRTUALENVWRAPPER_PYTHON.

如您所见,该变量$VIRTUALENVWRAPPER_PYTHON指向错误的 python 路径。所以我们需要重新设置变量的路径$VIRTUALENVWRAPPER_PYTHON

  1. export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python
  1. export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python

now run the following the command:

现在运行以下命令:

source /usr/local/bin/virtualenvwrapper.sh