1

I installed virtualenv using the command sudo pip install virtualenv and the installation is successful. Later, when I type virtualenv, I get the error message as following, -bash: virtualenv: command not found

The virtualenv is installed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. I see the similar questions in the forum with no definitive answers.

Python is in the location /usr/local/bin/python and I have version 2.7.9. I get the following using ls -l command,

enter image description here Why do I see the virtualenv is not found and how to solve the issue ?

UPDATE:

I use the command

ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py to put the virtualenv.py

inside the /usr/local/bin folder. Previously, I only did the same for the virtualenv file. Now, when I put the command virtualenv in the terminal, I get

-bash: /usr/local/bin/virtualenv: Permission denied.

I later use

sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py

and the say message keep showing. which virtualenv still returns nothing.

2
  • 2
    What I suspect is happening is that the virtualenv executable isn't being copied or symlinked to your /usr/local/bin folder. If you can locate the executable inside the site-packages, try symlinking it to /usr/local/bin Commented Jun 9, 2016 at 14:13
  • What do you mean ? I just checked inside the /usr/local/bin folder and there is no virtualenv. Should I copy from the site-packages and put inside the 'bin' folder ? Commented Jun 9, 2016 at 14:30

4 Answers 4

3

Pursuant to @Jason's suggestion, try making the symbolic link for virtualenv in the /bin directory like so:

ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv /usr/local/bin/virtualenv
Sign up to request clarification or add additional context in comments.

11 Comments

I did that and now I see virtualenv inside the /usr/local/bin folder. However, when I provide the commands virtualenv or which virtualenv, nothing returns in the Mac terminal. I closed the terminal and started again. No help with that as well. Now ?
I can't take this as answer unless it helps to solve the problem.
Check the permissions in the bin folder with ls -l.
that screenshot above is not from /usr/local/bin, but rather from the user home directory. If you're running chmod in the home dir, it will not be able to find the virtualenv execurable.
Can you provide a new screen shot of what the ls -l in usr/local/bin shows?
|
0

Why don't re-install virtualenv? Also try to use the latest version of pip (sudo pip install -U pip).

4 Comments

Do I need to uninstall pip and then to install again ?
Okay, I follow your instructions, but, no help here. After upgrading the pip, I get the message, Requirement already up-to-date: pip in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg
But have you re-installed virtulenv after that?
Yes, I also re-installed the virtualenv
0

Not sure if the answer will be useful to you, as i see the question is a few month old, but maybe it will be helpful for others.

I encountered the same problem, after installing python3.5 and pyCharm on my Mac. I moved the 3.5 folder from /Library/Frameworks/Python.framework/Versions/3.5 to /System/Library/Frameworks/Python.framework/Versions/3.5, following this guide, after disabling the System Integrity Protection first with reboot into recovery mode (boot with ctrl+R), and executing csrutil disable in the terminal. After reboot it was possible to move the python3.5 folder, and then i followed the guide, and everything worked like charm. In pyCharm i could choose the version 3.5 from /System/... instead of /Library/... (however, i still left a soft link in /Library/... to the /System folder where the python3.5 now was, just in case), and after adding the path to my zsh i could execute pip3 install virtualenv. So far so good.

Next, i tried to create the environment with virtualenv -p python3 env, and here i had the same problem as you. It seemed like the path could not be added somehow. Initially i also tried to look in the /System/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ and include it in the $PATH, then also create softlinks to virtualenv.py as you tried too, but finally found that although all the files are in the site-packages folder, the actual executable was in /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv. As the path there was included in my $PATH, i have no idea why it did not execute when typing virtualenv -p python3 env, even with sudo as you tried too, but once i typed the full path /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv -p python3 env, it worked like charm again.

I still have no idea why, but it worked and now i can move on :)

Hope it helps, and hope someone can explain this better than me.

Comments

0

You are created the symbolic link to the wrong file. As far as I know virtualenv is installed to /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv, (you can change the numbers for your Python version) so the command for creating the symbolic link should be:

ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv

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.