pip: pip does not support spaces in directories names

under Mac OS X 10.7

tareks:tmp tarek$ mkdir "some space"
tareks:tmp tarek$ cd some\ space/
tareks:some space tarek$ virtualenv --no-site-packages .
The --no-site-packages flag is deprecated; it is now the default behavior.
New python executable in ./bin/python
Installing setuptools............done.
Installing pip...............done.
tareks:some space tarek$ bin/pip install docutils
-bash: bin/pip: "/private/tmp/some: bad interpreter: No such file or directory

Or maybe that’s virtualenv ?

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Reactions: 6
  • Comments: 46 (31 by maintainers)

Commits related to this issue

Most upvoted comments

For folks looking for a simpler solution, I got https://github.com/pypa/pip/issues/923#issuecomment-19655227 to work pretty well, in a simpler mode. I only ever needed to call pip once (during an install script), so instead of saying

virtualenv .env
.env/bin/activate
pip install -r requirements.txt

I did

virtualenv .env
.env/bin/activate
python .env/bin/pip install -r requirements.txt

Solved my my problem - still a challenge to call pip outside of the script, but the incision is more narrow.

I’m not really into Python and this just confirmed I don’t want to be. It’s taken 4 years to add support for a space, and only to some platforms.

Thanks for the release @vsajip!

This fix will be shipping as a part of pip 10.

I have this problem on Windows 7 and quoting the path in the shebang line does not help. I find it pretty shocking that in 2017 we still develop software that falls flat on its face when encountering a space.

@smoothmango Would another option be to run python -m pip (or python3 -m pip) rather than pip?

Seems to be one way the docs specify to run it: https://pip.pypa.io/en/stable/installing/#upgrading-pip

When time allows, so it might be sometime in early September.

That works well. ^.^

FTR - I just ran the test-suite of pip after vendoring the latest distlib and all tests passed.


I guess that means this would be shipping as a part of pip 10 – adding to the milestone. 😃

@vsajip Could you cut a new release from the current master of distlib?

When time allows, so it might be sometime in early September. There are a couple of distlib issues I’m working on and would like to resolve before the next release.

N.B. recent updates of distlib (not yet released, but available in the source repository) use special mechanisms to specify very long paths or paths with spaces in scripts installed using ScriptMaker. It might be worth testing this with pip.

Just to quote myself here…

I guess […] this would be shipping as a part of pip 10

I find it pretty shocking that after decades of agony developers still use spaces in paths and expect it to work 😃

This is a long standing issue with many facets. The person who fixes it upstream will be revered and adored like no other, maybe something is happening already?

I’m highly interested in complicated path support so I give it a try. Here are my steps on Arch Linux and MacPorts, hoping that helps others.

$ hg clone https://bitbucket.org/pypa/distlib
$ git clone https://github.com/pypa/pip
$ git clone https://github.com/pypa/virtualenv
$ pushd pip
$ rm -rf pip/_vendor/distlib
$ cp -r ../distlib/distlib pip/_vendor/
$ python setup.py bdist_wheel  # this step requires python-wheel package on Arch Linux or py27-wheel/py36-wheel with MacPorts
$ popd
$ pushd virtualenv
$ rm virtualenv_support/pip-9.0.1-py2.py3-none-any.whl
$ cp ../pip/dist/pip-10.0.0.dev0-py2.py3-none-any.whl virtualenv_support

Now we can use the modified virtualenv package:

$ python ./virtualenv.py "v e n v"
$ source ./v\ e\ n\ v/bin/activate
$ pip --version
pip 9.0.1 from /home/yen/Projects/virtualenv/v e n v/lib/python3.6/site-packages (python 3.6)

I just got bit by this. Unfortunately, quoting in spaces nor escaping with backslashes fixes the problem.

I am incredibly dismayed to find that OS X does not support a shebang with spaces in the interpreter path! Gah!

I had to come up with an incredibly lame hack:

cd virtualenv/bin mv pip .real_pip vim pip

I then populated pip with the following:

#!/bin/bash

“/Users/jpepas/Developer/Peepcode/Meet Jquery/flask/virtualenv/bin/python” “/Users/jpepas/Developer/Peepcode/Meet Jquery/flask/virtualenv/bin/.real_pip” $@

So the only bullet-proof workaround I see is for each of the scripts which use a shebang (for my setup, that’s pip, pip-2.7, easy_install, easy_install-2.7) to be replaced by this level-of-indirection hack.

I feel dirty now.

(update 2017/5/28: just to be clear, my dismay is directed at Apple, this isn’t the virtualenv team’s fault.)