I am using python on MacOS and I have a problem to setup a python2.7 environment. I have installed both python2.7 and python3.6 on the system. And run below code to setup python2.7 env. I am not sure why I get this error. From the output I see it is using /anaconda/lib/python3.6
directory. How can I make it to use python2.7
environment?
$ 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)
setup two virtual environments for Python 2.7 and 3.6. Launce anaconda navigator and install spyder 3.3. 6 on both the environments Launch spyder on the environment with Python 3.6 Preferences-->Python Interpreter --> set the Python path for 2.7 Restart Spyder Done!
Python and OS Compatibility. virtualenv works with the following Python interpreter implementations: CPython versions 2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10.
I used the following commands in order C:\>python27\Scripts\pip.exe --version pip 8.1. 1 from c:\python27\lib\site-packages (python 2.7) C:\>python27\Scripts\pip.exe install virtualenv Collecting virtualenv and it prints nothing else.
Since you already have Anaconda installed, you can create a Python virtual environment by executing the following command in the terminal-
conda create -n pythonenvname python=x.x anaconda
Because you are trying to create a Python 2.7 virtual environment, I would suggest you using python27
as your environment name for convenience. Moreover, x.x
refers to the version of Python that would be used to create the environment. In your case, it's 2.7
.
So this is the command you should run to set up your virtual environment-
conda create -n python27 python=2.7 anaconda
After you have installed the environment, run the following command to activate it-
source activate python27
Now, if you run any python command, for example, python helloworld.py
, then the Python 2.7 interpreter would be used.
To deactivate the Python environment and return to your default one, simply execute the following command-
source deactivate
For further reference, check out this site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With