16

All seems to work just fine for both python 2 and 3:

$ which Python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

$ python --version
Python 2.7.9

$ python2
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

$ python3
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

My .bash_profile settings are as follows:

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH

The problem:

$ virtualenv My_Env
-bash: /usr/local/bin/virtualenv: /usr/local/opt/python3/bin/python3.4: bad interpreter: No such file or directory

The path above does not exist. I downloaded my python packages directly from the python site and installed using the default settings.

Prior to this, I used Python installed with HomeBrew, but this path does not appear to be a brew file path anyway.

Bottom line... My file path is messed up somewhere other than in my .bash_profile and I have no idea where to look to fix it.


Also note that I set up my other computer with the same exact .bash_profile and python installations and it works perfectly...

Both are running Mac Yosemite.

Thanks in advance!

6
  • What is in /usr/local/opt/python3 ? Commented Apr 20, 2015 at 1:04
  • There is no python3 in /usr/local/opt/ Commented Apr 20, 2015 at 1:07
  • check for export VIRTUALENV_PYTHON= in your bash files. Commented Apr 20, 2015 at 1:08
  • DT, export VIRTUALENV_PYTHON= is not there; should it be? Commented Apr 20, 2015 at 1:12
  • No, I was thinking that there might be an env setting for the default python for your virtualenv. Glad you found your answer. Commented Apr 20, 2015 at 1:18

4 Answers 4

12

Ok, I was able to fix the problem with a fresh install of virtualenv. I assume that is where the path issue was located (somewhere in the installation of virtualenv).

Sign up to request clarification or add additional context in comments.

3 Comments

VIRTUALENV and home brew may have been using the same path to python three, causing problems in VIRTUALENV when you home-brew installed python 3.
Yep. I installed virtualenv prior to using the installations from Python.org. So, I think virtualenv was using the original path rather than the new. :)
It might also help to source ~/.bash_profile after the virtualenv fresh install. It worked for me.
7

My problem was as simple as having spaces in the directory at the top of venv/bin/pip which meant that the path was inside quotes. As soon as I made sure that it wasn't under a directory with spaces and removed the quotes it worked.

eg. #!"/Users/Tomm/MY PROJECT/venv/bin/python" should be changed to #!/Users/Tomm/MY-PROJECT/venv/bin/python

2 Comments

Thanks! I was going absolutely nuts here after a good 30 #$!@@ minutes trying to fix this issue with pip.
Was having this problem on OS X and in a Linux VM. Definitely no spaces in directory names!
1

You can check the "activate" file in your virtualenv bin folder, and see what is written there at around line 42, and then can actually manually set it, while keeping in mind that all the executables in this bin folder are hard coded for the first shebang line.

You will need to change them as well. Or just move the folder to the right place for you current temporary task, otherwise you might need a virtualenv relocation tool or just re-install it.

Comments

1

Re-installing virtualenv should solve this. I also went through same bug and reinstalling using pip solved this for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.