2

I have been trying to set up virtualenv for use with django, but I keep having issues installing virtualenv with pip.

jeff@jeff-HP-MacBook-Android:~/repos$ pip install virtualenv
Collecting virtualenv
  Using cached virtualenv-13.1.2-py2.py3-none-any.whl
Installing collected packages: virtualenv
Exception:
Traceback (most recent call last):
  File "/home/jeff/.local/lib/python2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/home/jeff/.local/lib/python2.7/site-packages/pip/commands/install.py", line 311, in run
    root=options.root_path,
  File "/home/jeff/.local/lib/python2.7/site-packages/pip/req/req_set.py", line 646, in install
    **kwargs
  File "/home/jeff/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 803, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/home/jeff/.local/lib/python2.7/site-packages/pip/req/req_install.py", line 998, in move_wheel_files
    isolated=self.isolated,
  File "/home/jeff/.local/lib/python2.7/site-packages/pip/wheel.py", line 339, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/home/jeff/.local/lib/python2.7/site-packages/pip/wheel.py", line 317, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/virtualenv.py'
jeff@jeff-HP-MacBook-Android:~/repos$ 

The closest answer I can find regards permissions inside the virtualenv: How to avoid "Permission denied" when using pip with virtualenv

But from what I can tell my issue is that there's something wrong with my install of pip, since I apparently don't even have virtualenv yet.

Community
  • 1
  • 1
Jeff
  • 83
  • 2
  • 9

1 Answers1

7

I don't think there's anything wrong with your pip installation. virtualenv is itself a Python module, and by default it goes in /usr/local/lib/python2.7/dist-packages, a folder for which your user does not have write permissions. If you have sudo access, it would be easiest to simply try:

sudo pip install virtualenv

Once you've done that, you should be able to create virtualenvs without needing to use sudo. Alternately, there are instructions here for making your own virtual environment, but it looks like you will likely need to do some manual editing of the script it directs you to download.

rumdrums
  • 1,322
  • 2
  • 11
  • 25
  • 1
    From what I understand that will do a global install of virtualenv but just about everything I have read on the topic recommends against that for most developement. That's why I thought it was probably a pip issue. – Jeff Dec 08 '15 at 20:39
  • @Jeff I think you're confusing the point, though. It's definitely recommended to not use sudo to install modules within your virtual environment... but right now, you're just trying to get the 'virtualenv' module installed on your system, which is what allows you to create separate Python environments -- it is these environments that you want your user or your application's user to have permissions to install. You need to have a system-level Python environment in order to install virtual Python environments and that system-level environment is usually only writable by root on Linux systems. – rumdrums Dec 09 '15 at 04:17
  • I think you're right about my confusion. I did end up doing what you suggested but I'm still a bit unsure of why many tutorials I read suggested the pip install sans sudo. – Jeff Dec 11 '15 at 04:34
  • @Jeff I think it's because the tutorials you're seeing -- like the one you linked to -- assume you already have the 'virtualenv' module installed on your system. [This](https://opensourcehacker.com/2012/09/16/recommended-way-for-sudo-free-installation-of-python-software-with-virtualenv/) is a link to tutorial that doesn't make this assumption.... Regardless, once you have the virtualenv module installed on your system, you can create virtual environments all day by typing 'virtualenv [environment name]' without sudo privileges, and that's the most important thing. – rumdrums Dec 11 '15 at 05:00
  • Thanks! I appreciate the clarification. – Jeff Dec 11 '15 at 06:34