我在MacOS上使用python,我在设置python2.7环境时遇到问题。我在系统上安装了python2.7和python3.6。并运行下面的代码来设置python2.7 env。我不知道为什么会出现这个错误。从输出中我看到它正在使用/anaconda/lib/python3.6
目录。如何才能使用python2.7
环境?
$ virtualenv --python=/usr/bin/python2.7 venv/
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in /Users/joey/dev/jump/jump-api/venv/bin/python2.7
Traceback (most recent call last):
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 2869, in <module>
main()
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 713, in main
symlink=options.symlink)
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 925, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 1231, in install_python
copy_exe_shared_libs_and_symlinks(executable, py_executable, home_dir)
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 2828, in copy_exe_shared_libs_and_symlinks
of = codefile(f, rpaths)
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 2799, in codefile
return machofile(file, list(initial_rpaths_transitive))
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 2422, in __init__
_, sos = zip(*mach_o_find_dylibs(file))
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 2386, in mach_o_find_dylibs
do_file(ofile, find_lc_load_dylib, offset_size(), results, regex)
File "/anaconda/lib/python3.6/site-packages/virtualenv.py", line 2355, in do_file
do_file(file, offset_size(offset, size), *args)
TypeError: do_file() takes at least 4 arguments (3 given)
答案 0 :(得分:4)
由于您已经安装了Anaconda,您可以通过在终端中执行以下命令来创建Python虚拟环境 -
conda create -n pythonenvname python=x.x anaconda
因为您正在尝试创建Python 2.7虚拟环境,所以为方便起见,我建议您使用python27
作为您的环境名称。此外,x.x
指的是用于创建环境的Python版本。在你的情况下,它是2.7
。
因此,这是您应该运行以设置虚拟环境的命令 -
conda create -n python27 python=2.7 anaconda
安装环境后,运行以下命令将其激活 -
source activate python27
现在,如果你运行任何python命令,例如python helloworld.py
,那么将使用Python 2.7解释器。
要停用Python环境并返回默认环境,只需执行以下命令 -
即可source deactivate
如需进一步参考,请查看this site。