Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python asks for older paths on mac after deleting duplicate python installation

I am having the below error after a clean installation of python via brew install python. The link belongs to a previous python installation which I deleted manually.

$ virtualenv ENV
python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory

I am using MacOS 10.7.3 and I installed virtualenv via pip:

$ sudo /usr/local/share/python/pip install virtualenv
 Downloading/unpacking virtualenv
 Downloading virtualenv-1.7.1.2.tar.gz (2.1Mb): 2.1Mb downloaded
 Running setup.py egg_info for package virtualenv

 warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
 Installing collected packages: virtualenv
 Running setup.py install for virtualenv

 warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
 Installing virtualenv script to /usr/local/share/python
 Successfully installed virtualenv
 Cleaning up...
$ virtualenv ENV
 python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory

How can I fix this?

Edit : I reinstalled MacOSx and now returned back to my previous status that made me delete the preinstalled python.

$ which python 
/Library/Frameworks/Python.framework/Versions/2.7/bin/python 
$ which pip /usr/local/bin/pip $ sudo pip install virtualenv
Downloading/unpacking virtualenv 
Downloading virtualenv-1.7.1.2.tar.gz (2.1Mb): 2.1Mb downloaded
Running setup.py egg_info for package virtualenv

warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
Installing collected packages: virtualenv
Running setup.py install for virtualenv

warning: no previously-included files matching '*.*' found under directory 'docs/_templates'
Installing virtualenv script to /usr/local/bin
Successfully installed virtualenv
Cleaning up...


$ python virtualenv.py ENV
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/‌​MacOS/Python: can't open file 'virtualenv.py': [Errno 2] No such file or directory

The virtualenv.py is located at /Library/Python/2.7/site-packages/virtualenv.py and /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/py2app/recipes/virtualenv.py but somehow python misses all.

Why there is so much mess? How should I proceed to fix this?

like image 581
cgl Avatar asked Apr 18 '12 15:04

cgl


2 Answers

I had the very same situation after done stupid thing of deleting whole /System/Library/Frameworks/Python.framework/ what results in error:

python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No such file or directory

I managed to restore it, because I had a earlier copy of my whole disk, and just by copy-pasting the whole Python.framework directory back.

I don't know how much it is system dependent, but if somebody would like to try do that the same way instead of reinstalling whole OS X, the whole Python.framework zipped from me is here: http://andilabs.com/Python.framework.zip

like image 110
andilabs Avatar answered Nov 15 '22 20:11

andilabs


It looks like you have deleted the Apple-supplied Python 2.7 that is part of OS X 10.7. That's a bad thing to do. You may have inadvertently broken parts of OS X that depend on it. In general, never delete anything in /usr (other than /usr/local) or in /System/Library. If you install a newer version of something, manage that via $PATH, not by deleting. The best long-term thing to do is reinstall what you've deleted; the safest way to do that is to reinstall OS X. A temporary workaround might be to move /usr/bin/python out of the way and replace it with a link to /usr/local/bin/python2.7 but you really should undo the damage to your system.

UPDATE: Now that you've restored the system Python (good!), we can get at your original issue. Without more information, I can only speculate but chances are that you are installing virtualenv to the wrong Python instance. Keep in mind that you need to install a copy of Distribute (or its predecessor, setuptools), which provides the easy_install command, and a separate copy of pip in every instance of Python that you want to use. If you use the easy_install that Apple ships with OS X, you will be installing to the Apple system Python. You mention using brew in a comment. If so, you should follow the instructions and recipes for it; that's why you have a package manager. But here's how you would install everything from scratch:

$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
$ curl -O http://python-distribute.org/distribute_setup.py
$ python distribute_setup.py
[...]
creating /Library/Frameworks/Python.framework/Versions/2.7.3_release_10.6/lib/python2.7/site-packages/distribute-0.6.26-py2.7.egg
Extracting distribute-0.6.26-py2.7.egg to /Library/Frameworks/Python.framework/Versions/2.7.3_release_10.6/lib/python2.7/site-packages
Adding distribute 0.6.26 to easy-install.pth file
Installing easy_install script to /Library/Frameworks/Python.framework/Versions/2.7/bin
Installing easy_install-2.7 script to /Library/Frameworks/Python.framework/Versions/2.7/bin

Installed /Library/Frameworks/Python.framework/Versions/2.7.3_release_10.6/lib/python2.7/site-packages/distribute-0.6.26-py2.7.egg
Processing dependencies for distribute==0.6.26
Finished processing dependencies for distribute==0.6.26
After install bootstrap.
Creating /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg-info
Creating /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools.pth
$ curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
$ python get-pip.py
$ which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
$ pip install virtualenv
[...]
    Installing virtualenv script to /Library/Frameworks/Python.framework/Versions/2.7/bin
Successfully installed virtualenv
Cleaning up...
$ which virtualenv
/Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv
$ virtualenv ENV
New python executable in ENV/bin/python
Installing setuptools............done.
Installing pip...............done.
$ source ENV/bin/activate
(ENV)$ which python
/Users/nad/ENV/bin/python
(ENV)$  
like image 34
Ned Deily Avatar answered Nov 15 '22 20:11

Ned Deily