53

I set up a virtualenv environment on my Mac, but cannot get Pip to install packages. It fails with the following error:

/Volumes/Macintosh: bad interpreter: No such file or directory

I tracked the problem down to there being a space in the path, as is answered here: https://stackoverflow.com/a/10873611/126564
(the path being /Volumes/Macintosh HD/Python/my_project)

But that's a bit of a problem. The proposed solution is to:

"just put your virtualenv environment in a path without a space,"

but the part with the space is the volume itself. All of my paths would have a space, unless I stored them in a directory of /. And I don't think "store your stuff outside of user space" is a good solution.

Is there a better solution to this?

Community
  • 1
  • 1
redwall_hp
  • 1,067
  • 2
  • 10
  • 18
  • 2
    Better solution - contribute a fix to virtualenv? – manojlds Mar 18 '13 at 08:29
  • 3
    It is an open issue at virtualenv project: https://github.com/pypa/virtualenv/issues/53 – Hugo Lopes Tavares Mar 18 '13 at 18:40
  • Manually escaping the paths in ./bin seems to work, so I left a comment to that effect in the issue tracker. I don't know if I want to try to contribute a fix or not, since I'm a bit of a Python newb. – redwall_hp Mar 18 '13 at 21:41
  • I had similar issue on my Windows when trying to get my program to run via windows + r. it kept giving me errno2 no such path or directory so needles to say I got fustrated trying to figure out how to make the shebang work with white spaces and just made a new project_folder for my programs directly on C:. The strange thing is that somehow pip works in cmd for getting modules even though my main folder for Python is within a path that has a folder with white spaces. – SideburnsG Feb 12 '17 at 18:14

6 Answers6

37

Trying this:

  • editing bin/activate, change VIRTUAL_ENV='/Volumes/Macintosh HD/Python/my_project', and change PATH="$VIRTUAL_ENV/bin:$PATH", to make it work in your environment. using echo $PATH to check if it works.
  • editing bin/pip and bin/easy_install, change first line in the two files to

    #!/usr/bin/env python

After above 2 steps, you'll make your virtualenv works(also pip/easy_install).

Vincent Wen
  • 1,822
  • 1
  • 15
  • 12
  • 1
    That seems to have done the trick. I was poking around the files, but didn't think to edit the pip and easy_install ones. I just inserted a backslash before the space and it seems to be working so far. – redwall_hp Mar 18 '13 at 20:34
  • 3
    After doing the above fixes, now my virtualenv is pointing to the wrong installation of python as specified by `virtualenv -p` – zakdances Aug 23 '13 at 00:15
  • 2
    You can also use `sed -i '/^#!/ s@".*/\([^/]\+\)"@/usr/bin/env \1@' env/bin/*` – Jon Gjengset Nov 25 '15 at 22:21
  • 3
    This question likely fixes the problem, but I frankly don't understand the instructions. Change PATH to *what*? Why? – nicbou May 13 '17 at 14:57
  • @NicolasBouliane Change it such that it works, obviously. – Michael Fulton May 16 '17 at 18:17
  • 12
    I wouldn't be asking that question if I knew what to change it to. – nicbou Jul 19 '17 at 11:23
  • 4
    @NicolasBouliane add a backslash before the space. So in this case, just change `VIRTUAL_ENV='/Volumes/Macintosh HD/Python/my_project'` to `VIRTUAL_ENV='/Volumes/Macintosh\ HD/Python/my_project'`. – Richard Jan 02 '18 at 18:17
18

Note that you don't have to use your project folder for virtualenv. For example, you can place your virtualenv into /tmp folder or any other folder without spaces:

virtualenv /tmp/temporary_virtualenv
virtualenv /home/my_envs/env_for_projectname
Oleksandr Fedorov
  • 1,213
  • 10
  • 17
11

I have yet another workaround - you just need to use pip package instead of pip script. For example:

python -m pip install .

or even:

python -m pip install -U pip

For me works like a charm and doesn't require changes in files.

Tupteq
  • 2,986
  • 1
  • 21
  • 30
5

Editing the bin/activate file and escaping the spaces worked for me. Edit and save the file, then run source bin/activate.

Leandro Lima
  • 101
  • 1
  • 6
  • You just have to put the \ before the spaces or parenthesis (e.g.: /Users/Name/Dropbox\ \(Personal \)/) – Leandro Lima Nov 20 '18 at 22:22
  • that didn't seem to work, maybe there's more than one file to edit? the answer would be better with a list –  Nov 21 '18 at 23:55
3

Unless you have an atypical drive setup on your Mac, the path /Volumes/Macintosh HD should be a symlink to /. In other words, instead of

$ virtualenv /Volumes/Macintosh\ HD/venvpath

you can just do

$ virtualenv /venvpath

Not that I'm trying to condone software not handling spaces in file names. I agree with Hugo's comment above: keep an eye on the relevant GitHub issue.

Community
  • 1
  • 1
duozmo
  • 1,698
  • 5
  • 22
  • 33
2

As of end of 2018 the latest versions of pip and virtualenv deal with spaces in venv dir correctly.

See https://github.com/pypa/virtualenv/issues/53#issuecomment-434461292 .

Greg Dubicki
  • 5,983
  • 3
  • 55
  • 68