2

I'm fairly new to python so please bear with me. I installed the virtual env created a new environment and everything very smooth(great). so when I try to pip freeze it gives me all the global packages that are installed and not only the environment im in. Then I try to install django and it does not let me. This is the error that gives me...

→ pip install django
Collecting django
  Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB)    
    100% |████████████████████████████████| 6.6MB 187kB/s 
Installing collected packages: django
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/basecommand.py", line 209, in main
status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/commands/install.py", line 317, in run
prefix=options.prefix_path,
  File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_set.py", line 732, in install
**kwargs
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 835, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
 File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/req/req_install.py", line 1030, in move_wheel_files
isolated=self.isolated,
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/wheel.py", line 344, in move_wheel_files
clobber(source, lib_dir, True)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/wheel.py", line 315, in clobber
ensure_dir(destdir)
File "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/utils/__init__.py", line 83, in ensure_dir
os.makedirs(path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/django'
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Juanto85
  • 33
  • 2
  • 10
  • 1
    Did you activate your environment first? i.e. `source YourVirtualEnvDirectory/bin/activate` – Curtis Olson May 02 '16 at 20:33
  • yes. Its activated. Just know (with my env activated) I pip installed it using sudo but what it did was install `django` globally. @CurtisOlson – Juanto85 May 02 '16 at 20:35
  • 1
    It does not look like "activate" went through. You can execute "which python" or "which pip" and it should print the path to the Python/Pip in your virtual env. – Praveen Yalagandula May 02 '16 at 20:40
  • @PraveenYalagandula it did go thru the name of the environment appears in terminal prompt. – Juanto85 May 02 '16 at 20:42
  • @CurtisOlson still giving me the same error. – Juanto85 May 02 '16 at 20:46
  • I imagine this issue is being caused by the permissions of your virtualenv. Try using the solution posted here by Jay Modi: http://stackoverflow.com/questions/30656046/permission-denied-error-when-using-pip-install-in-virtualenv – Curtis Olson May 02 '16 at 20:50
  • @CurtisOlson for a moment I thought it was maybe because Im not using bash shell im using zsh but then I remembered Ive had it working before in another machine with zsh. – Juanto85 May 02 '16 at 20:57
  • what is the output of "which pip" in your virtualenv? – Praveen Yalagandula May 02 '16 at 21:30
  • as others have pointed out in earlier comments. you are not in the virtualenv this clearly shows it to be so: "/Library/Python/2.7/site-packages/pip-8.1.1-py2.7.egg/pip/basecommand.py" – e4c5 May 02 '16 at 23:41
  • @e4c5 I uninstalled it and installed it back to see if maybe some installation problem and it keeps doing the same thing. Is there another way to check other than the prompt change when youre in the environment? – Juanto85 May 03 '16 at 14:12

1 Answers1

0

OK. I got it working. The problem was something with a cache directory. When I reinstalled virtualenv I used a flag plus sudo.

sudo pip install --no-cache-dir virtualenv

but new questions comes up.

  • How important is a cache directory for the environments?
  • Do I need one yes o no?

Thanks all for your awesome help.

Juanto85
  • 33
  • 2
  • 10