I have already wasted several hours on this issue and am trapped. Could anyone help me out? Thanks.
I have both Python 2.7.10 and Python 3.4 installed in my Macbook through Homebrew. At the same time, the macbook has its default 2.7.6 which is to be avoided as it does not bundle with pip.
Python 3.4 is symbolick
/usr/local/bin/python3
../../../Library/Frameworks/Python.framework/Versions/3.4/bin/python3
Python 2.7.10 is
/usr/local/bin/python2
/usr/local/Cellar/python/2.7.10_2/bin/python
Now, I have python 2.7 web app to run. Naturally, I need to create a virtual environment by python 2.7.10.
Either
1) create a python 2.7 virtual environment
Steps I researched are:
a. pip install virtualenv
b. virtualenv -p /usr/local/bin/python2 <path/to/new/virtualenv/>
However, in step a, there is error:
~ $/usr/local/Cellar/python/2.7.10_2/bin/pip install virtualenv
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.10_2/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
Or
2) Use python 2.7 in virtual environment created by Python 3.4. Does anyone know how to choose python 2.7 inside the virtual environment created by Python 3.4?
I use this link to create virtual environment in Python 3.4
https://docs.python.org/3/library/venv.html
UPDATE: Thanks for both answers. I resolved the Question 1).
Essentially, you need to add --user when installing the setuptools and virtualenv. For example,
~ $pip install virtualenv==1.5.2 --user
Here is my test results:
~ $virtualenv -p /usr/local/bin/python2 test_python2/
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 5, in <module>
from pkg_resources import load_entry_point
File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 3084, in <module>
File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 3070, in _call_aside
File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 3097, in _initialize_master_working_set
File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 653, in _build_master
File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 666, in _build_from_requirements
File "build/bdist.macosx-10.10-intel/egg/pkg_resources/__init__.py", line 839, in resolve
pkg_resources.DistributionNotFound: The 'virtualenv==1.5.2' distribution was not found and is required by the application
~ $
~ $
~ $virtualenv -p /usr/local/bin/python2 test_python2/
Running virtualenv with interpreter /usr/local/bin/python2
New python executable in test_python2/bin/python2.7
Also creating executable in test_python2/bin/python
Installing setuptools..................done.
~ $ls test_python2/
bin include lib
~ $
~ $cd test_python2/
~/test_python2 $source bin/activate
(test_python2)~/test_python2 $
(test_python2)~/test_python2 $python
Python 2.7.10 (default, Jul 13 2015, 12:05:58)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
(test_python2)~/test_python2 $
(test_python2)~/test_python2 $