2017-07-10 102 views
4

我使用在MacOS Python和我必須設置一個問題python2.7環境。我已經在系統上安裝了python2.7和python3.6。並運行下面的代碼來設置python2.7環境。我不知道爲什麼我得到這個錯誤。從輸出我看到它使用/anaconda/lib/python3.6目錄。我怎樣才能讓它使用python2.7環境?如何通過virtualenv創建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

您正在使用Anaconda ...你見過[documentations](https://conda.io/docs/using/envs.html)嗎? – Pouria

+0

我如何使用的virtualenv,而不是蟒蛇的? –

回答

3

既然你已經安裝了蟒蛇,您可以創建由終點碼頭

conda create -n pythonenvname python=x.x anaconda 

執行以下命令,因爲你要創建一個Python 2.7的虛擬環境Python的虛擬環境中,我將使用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