Using virtualenv with spaces in a path

PythonMacosVirtualenvPip

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

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).

Solution 2 - Python

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

Solution 3 - Python

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.

Solution 4 - Python

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

Solution 5 - Python

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.

Solution 6 - Python

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 .

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionredwall_hpView Question on Stackoverflow
Solution 1 - PythonVincent WenView Answer on Stackoverflow
Solution 2 - PythonOleksandr FedorovView Answer on Stackoverflow
Solution 3 - PythonTupteqView Answer on Stackoverflow
Solution 4 - PythonLeandro LimaView Answer on Stackoverflow
Solution 5 - PythonduozmoView Answer on Stackoverflow
Solution 6 - PythonGreg DubickiView Answer on Stackoverflow