3

I am trying to install a fresh version of virtualenv (there is some problem with the path that python has stored in sys.executable) and it turns out there is another problem that actually seems related.

When I try to run pip install virtualenv, I get this output:

-bash: /usr/local/Cellar/python/2.7.10_2/bin/pip: /usr/local/opt/python3/bin/python3.4: 
bad interpreter: No such file or directory

Now my original point in reinstalling virtualenv is that I keep getting this error when I run virtualenv venv

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 2363, in <module>
    main()
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 832, in main
    symlink=options.symlink)
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 994, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "/Library/Python/2.7/site-packages/virtualenv.py", line 1288, in install_python
    shutil.copyfile(executable, py_executable)
  File "/usr/local/Cellar/python3/3.4.3_2/Frameworks/Python.framework/Versions/3.4/lib/python3.4/shutil.py", line 108, in copyfile
    with open(src, 'rb') as fsrc:
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/opt/python3/bin/python3.4'

As a sidenote that may be relevant, rather than using the default installed python3, I brew-installed a python3 with a brewed openssl (an application required it) and placed the path of the brewed python3 at the top of my /etc/paths.

I have tried to install and uninstall python multiple times without any success and am completely at a loss of what the problem could be. Any direction would be greatly appreciated.

EDIT After @cel 's suggestions, it turned out that the head of my pip file (located at /usr/local/Cellar/python/2.7.10_2/bin/pip) was set to hardcode a python version as so #!/usr/local/opt/python3/bin/python3.4. I changed this to the output of which python which was /usr/local/Cellar/python/2.7.10_2/bin/python

This allowed me to succesfully create a virtualenv once again. Thanks!

8
  • 1
    does echo $PYTHONPATH print anything?
    – cel
    Sep 30, 2015 at 5:23
  • 1
    It does not, I just get an empty line
    – OKUZA
    Sep 30, 2015 at 5:31
  • I have python2.7 installed under a similar scheme (path in /etc/paths, etc.)
    – OKUZA
    Sep 30, 2015 at 5:32
  • What is the output of head -1 /usr/local/Cellar/python/2.7.10_2/bin/pip?
    – cel
    Sep 30, 2015 at 5:35
  • Also the output of python -E -m pip -V and python -E -m pip -V may be interesting.
    – cel
    Sep 30, 2015 at 5:46

1 Answer 1

3

I came across a similar problem when I used HomeBrew to upgrade my python from version 3.5.2 to version 3.6.0. HomeBrew updated the symlink /usr/local/bin/pip3 to /usr/local/Cellar/python3/3.6.0/bin/pip3 but my /usr/local/bin/pip was still using the old script and it was pointing to the python interpreter at /usr/local/opt/python3/bin/python3.5.

My course of action was as follows:

  1. Unlinked /usr/local/bin/pip and updated it to point /usr/local/Cellar/python3/3.6.0/bin/pip3.

  2. Created a new symlink /usr/local/bin/pip3.5 that pointed to /usr/local/Cellar/python3/3.5.2/bin/pip3 and updated the header of pip3.5 script to point to the python interpreter at /usr/local/Cellar/python3/3.5.2/bin/python3.5

  3. Followed the same procedure for virtualenv.

P.S. Initially I didn't face this problem with virtualenv since I was using it with the -p option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.