0

I tried to start virtualenv WITHOUT sudo but unfortunately it cannot find (Permission denied) /lib/python2.7/site-packages/easy_install.py. So I did:

sudo virtualenv name_env

The problem is that now pip is the global version (not inside pip): which pip: /usr/local/bin/pip So I cannot install any package inside the environment. If I start virtualenv without sudo:

virtualenv name_env

OSError: Command /Users/andrea/package_lambda/bin/python2.7 -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip wheel failed with error code 2 Any suggestion?

asasa178
  • 221
  • 1
  • 11
  • If any of the answers address your question, please mark it as such so that the thread is closed and the question appears as answered on the board. – Pouria Feb 09 '16 at 18:56

4 Answers4

1

Don't use sudo just because you can!

I suggest you install another Python environment using brew, and then install pip, and subsequently virtualenv. This way, you'll substantially correct the underlying problem.

I would follow this method:

brew install pyenv

pyenv install 2.7.11

Or check the available versions through:

pyenv versions

This way, you can install different versions and switch between them as you wish, for instance:

pyenv global 2.7.11

And then you can install pip like so:

python -m easy_intall pip

and then install virtualenv like so:

python -m pip install virtualenv
Pouria
  • 1,081
  • 9
  • 24
  • Thanks for the answer. However python easy_install -m pip: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'easy_install': [Errno 2] No such file or directory – asasa178 Feb 09 '16 at 21:40
  • Apologies. I had a typo in the command. I just corrected it. It is `python -m easy_install pip`, not `python easy_install -m pip`. My bad. – Pouria Feb 09 '16 at 22:06
  • I got permission denied (because I'm not using sudo): [Errno 13] Permission denied: '/lib/python2.7/site-packages/test-easy-install-22088.write-test' – asasa178 Feb 09 '16 at 22:52
  • Download Python from python.org and install it. You appear to be having permission issues for some reason. – Pouria Feb 09 '16 at 23:19
  • I download and installed the last version 2.7.11 Of course it asked my password so I guess it's equivalent to sudo.... I don't get how can you install software in the lib folder without sudo. – asasa178 Feb 09 '16 at 23:30
  • For that yes, it does ask you for the user password. Sudo is not the same as user password. – Pouria Feb 09 '16 at 23:47
  • Anyway thanks even though the problem is still there. I can write in the lib folder without sudo and I can create a virtualenv without sudo. – asasa178 Feb 10 '16 at 00:13
0

As pouria mentioned, I believe it's a good idea to make sure you installed virtualenv using pip in the first place. I also agree that on OSX, using sudo should be rare.

As mentioned on a previous answer, you should also check that the files in the bin of your virtual env are correct.

Community
  • 1
  • 1
nlloyd
  • 1,966
  • 2
  • 15
  • 18
  • Thanks for the answer but yes the path VIRTUAL_ENV is correct and virtualenv has been installed using pip – asasa178 Feb 09 '16 at 21:44
0

I found the solution myself. I was using iterm instead of terminal (standard mac OS X). Using terminal I did:

sudo pip uninstall virtualenv
sudo pip install virtualenv
sudo cp /usr/local/bin/virtualenv /bin/virtualenv

Then I can create start a virtualenv:

virtualenv name_env
source name_env/bin/activate

To install python package on it I use:

sudo pip install --target=name_env/lib/python2.7/site-packages/ package name
asasa178
  • 221
  • 1
  • 11
0

I have the following file ~/.pydistutils.cfg with the contents

[install]
prefix=

temporarily removing this file fixed the issue for me (i had this file in place to address a different issue)

Alex
  • 5,141
  • 12
  • 26