Virtualenv 与此系统或可执行文件不兼容

Posted

技术标签:

【中文标题】Virtualenv 与此系统或可执行文件不兼容【英文标题】:Virtualenv not compatible with this system or executable 【发布时间】:2017-11-18 10:46:17 【问题描述】:

尝试在我的 mac OSX 10.10.05 上创建一个虚拟环境

从终端运行,已经在其他计算机上成功地在 linux 和 windows OS 上制作了 VirtualEnv。

尝试通过向我的 bash 配置文件添加 WORK_ON 路径来解决此问题,但未解决。在线论坛似乎没有解决这个问题,建议使用 mkvirtualenv,它似乎不是每个 pip、conda 和 easy_install 的可下载包......

无论如何,如果您能提供帮助,我们将非常感激。

这是终端输出:

joshua ~ $ pip install --upgrade virtualenv
Requirement already up-to-date: virtualenv in ./anaconda/lib/python3.5/site-packages
joshua ~ $ virtualenv -p python3 test
Running virtualenv with interpreter /Users/joshua/anaconda/bin/python3
Using base prefix '/Users/joshua/anaconda'
New python executable in /Users/joshua/test/bin/python3
Also creating executable in /Users/joshua/test/bin/python
ERROR: The executable /Users/joshua/test/bin/python3 is not functioning
ERROR: It thinks sys.prefix is '/Users/joshua' (should be '/Users/joshua/test')
ERROR: virtualenv is not compatible with this system or executable

...尝试卸载 virtualenv

  Successfully uninstalled virtualenv-15.1.0
joshua ~ $ pip install virtualenv
Collecting virtualenv
  Using cached virtualenv-15.1.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.1.0
joshua ~ $ virtualenv test -v
Using base prefix '/Users/joshua/anaconda'
Creating /Users/joshua/test/lib/python3.5
Symlinking Python bootstrap modules
  Symlinking /Users/joshua/test/lib/python3.5/config-3.5m
  Symlinking /Users/joshua/test/lib/python3.5/lib-dynload
  Symlinking /Users/joshua/test/lib/python3.5/plat-darwin
  Symlinking /Users/joshua/test/lib/python3.5/os.py
  Ignoring built-in bootstrap module: posix
  Symlinking /Users/joshua/test/lib/python3.5/posixpath.py
  Cannot import bootstrap module: nt
  Symlinking /Users/joshua/test/lib/python3.5/ntpath.py
  Symlinking /Users/joshua/test/lib/python3.5/genericpath.py
  Symlinking /Users/joshua/test/lib/python3.5/fnmatch.py
  Symlinking /Users/joshua/test/lib/python3.5/locale.py
  Symlinking /Users/joshua/test/lib/python3.5/encodings
  Symlinking /Users/joshua/test/lib/python3.5/codecs.py
  Symlinking /Users/joshua/test/lib/python3.5/stat.py
  Cannot import bootstrap module: UserDict
  Cannot import bootstrap module: copy_reg
  Symlinking /Users/joshua/test/lib/python3.5/types.py
  Symlinking /Users/joshua/test/lib/python3.5/re.py
  Cannot import bootstrap module: sre
  Symlinking /Users/joshua/test/lib/python3.5/sre_parse.py
  Symlinking /Users/joshua/test/lib/python3.5/sre_constants.py
  Symlinking /Users/joshua/test/lib/python3.5/sre_compile.py
  Cannot import bootstrap module: _abcoll
  Symlinking /Users/joshua/test/lib/python3.5/warnings.py
  Symlinking /Users/joshua/test/lib/python3.5/linecache.py
  Symlinking /Users/joshua/test/lib/python3.5/abc.py
  Symlinking /Users/joshua/test/lib/python3.5/io.py
  Symlinking /Users/joshua/test/lib/python3.5/_weakrefset.py
  Symlinking /Users/joshua/test/lib/python3.5/copyreg.py
  Symlinking /Users/joshua/test/lib/python3.5/tempfile.py
  Symlinking /Users/joshua/test/lib/python3.5/random.py
  Symlinking /Users/joshua/test/lib/python3.5/__future__.py
  Symlinking /Users/joshua/test/lib/python3.5/collections
  Symlinking /Users/joshua/test/lib/python3.5/keyword.py
  Symlinking /Users/joshua/test/lib/python3.5/tarfile.py
  Symlinking /Users/joshua/test/lib/python3.5/shutil.py
  Symlinking /Users/joshua/test/lib/python3.5/struct.py
  Symlinking /Users/joshua/test/lib/python3.5/copy.py
  Symlinking /Users/joshua/test/lib/python3.5/tokenize.py
  Symlinking /Users/joshua/test/lib/python3.5/token.py
  Symlinking /Users/joshua/test/lib/python3.5/functools.py
  Symlinking /Users/joshua/test/lib/python3.5/heapq.py
  Symlinking /Users/joshua/test/lib/python3.5/bisect.py
  Symlinking /Users/joshua/test/lib/python3.5/weakref.py
  Symlinking /Users/joshua/test/lib/python3.5/reprlib.py
  Symlinking /Users/joshua/test/lib/python3.5/base64.py
  Symlinking /Users/joshua/test/lib/python3.5/_dummy_thread.py
  Symlinking /Users/joshua/test/lib/python3.5/hashlib.py
  Symlinking /Users/joshua/test/lib/python3.5/hmac.py
  Symlinking /Users/joshua/test/lib/python3.5/imp.py
  Symlinking /Users/joshua/test/lib/python3.5/importlib
  Symlinking /Users/joshua/test/lib/python3.5/rlcompleter.py
  Symlinking /Users/joshua/test/lib/python3.5/operator.py
  Symlinking /Users/joshua/test/lib/python3.5/_collections_abc.py
  Symlinking /Users/joshua/test/lib/python3.5/_bootlocale.py
Creating /Users/joshua/test/lib/python3.5/site-packages
Writing /Users/joshua/test/lib/python3.5/site.py
Writing /Users/joshua/test/lib/python3.5/orig-prefix.txt
Writing /Users/joshua/test/lib/python3.5/no-global-site-packages.txt
Creating parent directories for /Users/joshua/test/include
Symlinking /Users/joshua/test/include/python3.5m
Creating /Users/joshua/test/bin
New python executable in /Users/joshua/test/bin/python
Changed mode of /Users/joshua/test/bin/python to 0o755
Testing executable with /Users/joshua/test/bin/python -c "import sys;out=sys.stdout;getattr(out, "buffer", out).write(sys.prefix.encode("utf-8"))"
ERROR: The executable /Users/joshua/test/bin/python is not functioning
ERROR: It thinks sys.prefix is '/Users/joshua' (should be '/Users/joshua/test')
ERROR: virtualenv is not compatible with this system or executable

这是当前的 bash_profile:

# Enable tab completion
source ~/git-completion.bash

# colors!
green="\[\033[0;32m\]"
blue="\[\033[0;34m\]"
purple="\[\033[0;35m\]"
reset="\[\033[0m\]"

# Change command prompt
source ~/git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
# '\u' adds the name of the current user to the prompt
# '\$(__git_ps1)' adds git-related stuff
# '\W' adds the name of the current directory
export PS1="$purple\u$green\$(__git_ps1)$blue \W $ $reset"

alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

# Add Path
export PATH="$HOME/anaconda/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:$PATH"
# export PATH=$PATH:/users/Joshua/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

# Locale 
$ export LC_ALL=en_US.UTF-8
$ export LANG=en_US.UTF-8

【问题讨论】:

类似问题有答案:***.com/questions/23842713/…底线,升级virtualenv:pip install --upgrade virtualenv 要求已经更新:./anaconda/lib/python3.5/site-packages 中的 virtualenv :/ which pipwhich virtualenv 怎么说?看起来您正在调用两个不同的 Python 解释器。 @9000 joshua ~ $ which python /Users/joshua/anaconda/bin/python joshua ~ $ which python3 /Users/joshua/anaconda/bin/python3 joshua ~ $ which pip /Users/joshua/anaconda/bin/pip joshua ~ $ which virtualenv /Users/joshua/anaconda/bin/virtualenv @9000,我让它工作了......必须用 pip 卸载 virtualenv,然后用 conda 重新安装 virtualenv。我不知道为什么这解决了这个问题,但作为一个学习练习(可能对我和其他人来说),你们知道为什么吗? 【参考方案1】:

我的有限理解是我的 python 解释器和包是在 Anaconda 下使用 Conda 包管理器管理的,而我的 virtualenv 最初是使用 pip 安装的。

用 pip 卸载 virtualenv 并用 conda 重新安装解决了这个问题

pip uninstall virtualenv

conda install virtualenv

【讨论】:

以上是关于Virtualenv 与此系统或可执行文件不兼容的主要内容,如果未能解决你的问题,请参考以下文章

解决无法将“xxxx”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。

Ubuntu出现”系统的网络服务与此版本的网络管理器不兼容,求帮助

如何在 Linux Ubuntu 12.04 上从 Python 调用脚本文件或可执行文件

确定 Linux 中二进制文件的目标 ISA 扩展名(库或可执行文件)

“$npm_execpath”未被识别为内部或外部命令、程序或可执行批处理文件

“错误无法找到浏览器。 “saucelabs:Chrome@83.0:Windows10”不是浏览器别名或可执行文件的路径