Skip to main content
 首页 » 编程设计

python之virtualenvwrapper.user_scripts 找不到 get_env_details

2025年05月04日23insus

当我运行 mkvirtualenv TESTING 时:

New python executable in TESTING/bin/python2.7 
Also creating executable in TESTING/bin/python 
Installing setuptools, pip, wheel...done. 
virtualenvwrapper.user_scripts could not run "/Users/admin/.virtualenvs/TESTING/bin/preactivate": [Errno 2] No such file or directory 

当我运行 lsvirtualenv 时出现类似的错误:

bpython-dev 
=========== 
virtualenvwrapper.user_scripts could not run 
"/Users/admin/.virtualenvs/bpython-dev/bin/get_env_details": [Errno 2] No such file or directory 

我检查了 .virtualenvs/bpython-dev/(和其他虚拟环境)以查看 get_env_details 是否存在,它确实存在。

这个问题是我在Mavericks上用Time Machine执行Migration Assistant后出现的。

我正在使用与 Homebrew 一起安装的 Python 2。 which python 产生 usr/local/bin/python 和 which pip 产生 usr/local/bin/pip。

我的.bash_profile:

# Load /usr/local/ before /usr/bin/ 
export PATH=/usr/local/bin:$PATH 
export PATH=$HOME/bin:$PATH 
 
 
# Load the default .profile 
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" 
 
 
# Virtualenvwrapper 
export WORKON_HOME=$HOME/.virtualenvs 
export PROJECT_HOME=$HOME/Hacker\ School/ 
export PIP_VIRTUALENV_BASE=$WORKON_HOME 
export PIP_RESPECT_VIRTUALENV=true 
source /usr/local/bin/virtualenvwrapper.sh  
 
 
# Timing terminal directory tracking 
PROMPT_TITLE='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"' 
export PROMPT_COMMAND="${PROMPT_COMMAND} ${PROMPT_TITLE}; " 
 
export DJANGO_COLORS="dark" 
 
 
# _django_completion() 
# { 
#     COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \ 
#                    COMP_CWORD=$COMP_CWORD \ 
#                    DJANGO_AUTO_COMPLETE=1 $1 ) ) 
# } 
# complete -F _django_completion -o default django-admin.py manage.py django-admin 
 
# _python_django_completion() 
# { 
#     if [[ ${COMP_CWORD} -ge 2 ]]; then 
#         PYTHON_EXE=${COMP_WORDS[0]##*/} 
#         echo $PYTHON_EXE | egrep "python([2-9]\.[0-9])?" >/dev/null 2>&1 
#         if [[ $? == 0 ]]; then 
#             PYTHON_SCRIPT=${COMP_WORDS[1]##*/} 
#             echo $PYTHON_SCRIPT | egrep "manage\.py|django-admin(\.py)?" >/dev/null 2>&1 
#             if [[ $? == 0 ]]; then 
#                 COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]:1}" \ 
#                                COMP_CWORD=$(( COMP_CWORD-1 )) \ 
#                                DJANGO_AUTO_COMPLETE=1 ${COMP_WORDS[*]} ) ) 
#             fi 
#         fi 
#     fi 
# } 
 
# # Support for multiple interpreters. 
# unset pythons 
# if command -v whereis &>/dev/null; then 
#     python_interpreters=$(whereis python | cut -d " " -f 2-) 
#     for python in $python_interpreters; do 
#         pythons="${pythons} ${python##*/}" 
#     done 
#     pythons=$(echo $pythons | tr " " "\n" | sort -u | tr "\n" " ") 
# else 
#     pythons=python 
# fi 
 
# complete -F _python_django_completion -o default $pythons 
# Setting PATH for Python 2.7 
# The orginal version is saved in .bash_profile.pysave 
PATH="usr/local/Cellar/python/2.7.10_2/bin/:${PATH}" 
export PATH 
 
# Homebrew, OpenCV 
export PATH="/usr/local/Cellar/opencv/2.4.9/lib/python2.7:$PATH" 
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH 

请您参考如下方法:

当这样的事情发生在我身上时,我通常会重新安装 Homebrew。在 SO 上查看此链接:Safest way to reinstall Homebrew

之后,您可能必须重新创建 Python Virtualenv(以选择正确的 Python 二进制文件和库)。