Cannot use paths with spaces in them

Bug #241581 reported by Jamie Kirkpatrick
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Virtualenv
Confirmed
Undecided
Unassigned

Bug Description

If you try to initialise a virtualenv in a path which contains spaces, easy_install will not run.

Suggested fix: quote path names when setting up the environment.

Revision history for this message
Ian Bicking (ianb) wrote :

I attempted to fix this in r3604, but I can't test (no Windows system). Can you confirm if this works? Just grab the trunk: http://svn.colorstudy.com/virtualenv/trunk/virtualenv.py

Changed in virtualenv:
status: New → In Progress
Revision history for this message
yvesm (yves-moisan) wrote :

I tested it today and it does not work. virtualenv_win32.py is the trunk version as of today and it outputs the same error as the virtualenv.py that comes with Virtualenv 1.3.2 :

C:\Program Files\My Dir>"C:\Program Files\My Dir\Python25\python" "C:\Program Files\My Dir\Python25\Lib\site-packages\virtualenv_win32.py" --no-site-packages "C:\Program Files\My Dir\TileCache"

New python executable in C:\Program Files\My Dir\TileCache\Scripts\python.exe
Traceback (most recent call last):
  File "C:\Program Files\My Dir\Python25\Lib\site-packages\virtualenv_win32.py", line 1208, in <module>
    main()
  File "C:\Program Files\My Dir\Python25\Lib\site-packages\virtualenv_win32.py", line 420, in main
    unzip_setuptools=options.unzip_setuptools)
  File "C:\Program Files\My Dir\Python25\Lib\site-packages\virtualenv_win32.py", line 663, in create_environment
    stdout=subprocess.PIPE)

  File "C:\Program Files\My Dir\Python25\lib\subprocess.py", line 594, in __init__
    errread, errwrite)

  File "C:\Program Files\My Dir\Python25\lib\subprocess.py", line 816, in _execute_child
    startupinfo)

WindowsError: [Error 3] The system cannot find the path specified

Revision history for this message
Ian Bicking (ianb) wrote :

I've committed what I think is a fix (untested on Windows) in r3795. This normalizes the path name using win32api.GetShortPathName which should remove the space.

Please confirm if this resolves the issue.

Changed in virtualenv:
status: In Progress → Fix Committed
Revision history for this message
AF (af09) wrote :

I am seeing this on Ubuntu 9.04 using both the version in the Ubuntu repo and r3879 as downloaded from http://svn.colorstudy.com/virtualenv/trunk

Changed in virtualenv:
status: Fix Committed → Confirmed
Revision history for this message
AF (af09) wrote :

To clarify:

The error I am seeing is:
bash: /media/Path with Spaces Drive/virt/bin/easy_install: " /media/Path: bad interpreter: No such file or directory

Revision history for this message
peter (pkoppatz) wrote :

Installed python26 and easy_install on Windows XP SP2

C:\home>virtualenv xxx
Traceback (most recent call last):
  File "C:\Python26\Scripts\virtualenv-script.py", line 8, in <module>
    load_entry_point('virtualenv==1.3.3', 'console_scripts', 'virtualenv')()
  File "C:\Python26\lib\site-packages\virtualenv-1.3.3-py2.6.egg\virtualenv.py",
 line 420, in main
    unzip_setuptools=options.unzip_setuptools)
  File "C:\Python26\lib\site-packages\virtualenv-1.3.3-py2.6.egg\virtualenv.py",
 line 499, in create_environment
    home_dir, lib_dir, inc_dir, bin_dir = path_locations(home_dir)
  File "C:\Python26\lib\site-packages\virtualenv-1.3.3-py2.6.egg\virtualenv.py",
 line 521, in path_locations
    import win32api
ImportError: No module named win32api

Now I replaced virtualenv.py from the egg with the version from:

http://svn.colorstudy.com/virtualenv/trunk/

Next Error:

C:\home>virtualenv xxx
New python executable in xxx\Scripts\python.exe
Traceback (most recent call last):
  File "C:\Python26\Scripts\virtualenv-script.py", line 8, in <module>
    load_entry_point('virtualenv==1.3.3', 'console_scripts', 'virtualenv')()
  File "C:\Python26\lib\site-packages\virtualenv-1.3.3-py2.6.egg\virtualenv.py",
 line 420, in main
    unzip_setuptools=options.unzip_setuptools)
  File "C:\Python26\lib\site-packages\virtualenv-1.3.3-py2.6.egg\virtualenv.py",
 line 503, in create_environment
    site_packages=site_packages, clear=clear)
  File "C:\Python26\lib\site-packages\virtualenv-1.3.3-py2.6.egg\virtualenv.py",
 line 643, in install_python
    pythonw = os.path.join(os.path.dirname(sys.executable, 'pythonw.exe'))
TypeError: dirname() takes exactly 1 argument (2 given)

Replaced the following lines...

virtualenv.py: Line 642-647 with:

        if sys.platform == 'win32' or sys.platform == 'cygwin':
            pythonw = sys.executable
            if os.path.exists(pythonw):
                logger.info('Also created pythonw.exe')
                shutil.copyfile(pythonw, py_executable)

Now it works.

Revision history for this message
Jamie Kirkpatrick (jamiekp) wrote :

I second what peter found. His fix also works for me: can this be applied to the trunk please?

Thanks

Jamie

Revision history for this message
Don Spaulding II (donspauldingii) wrote :

The simplest solution that works seems to be changing:

os.path.join(os.path.dirname(sys.executable, 'pythonw.exe'))

To:

os.path.join(os.path.dirname(sys.executable), 'pythonw.exe')

On lines 643 and 646 of virtualenv.py in trunk.

Revision history for this message
Chris McNabb (raizyr) wrote :

I'm also having this problem on Mac, since the problem isn't specific to windows, perhaps there's a solution that isn't dependent on sys.platform == 'win32' or 'cygwin'

Revision history for this message
Chris McNabb (raizyr) wrote :

on further reflection, the problem AF and I are having is slightly different, the initialization of a new virtualenv works, however running easy_install after activiating that virtualenv results in an error

(virtualenv)triumph:python raizyr$ easy_install twisted
-bash: /Users/raizyr/Library/Application Support/TextMate/Bundles/Hswi.tmbundle/Support/python/virtualenv/bin/easy_install: "/Users/raizyr/Library/Application: bad interpreter: No such file or directory

Revision history for this message
Chris McNabb (raizyr) wrote :

Okay, it seems the "bad interpreter" error is a bash thing, it doesn't allow spaces in the interpreter path.

Here's a thread discussing it, http://<email address hidden>/msg03969.html

A workaround is simply to call the script with python

(virtualenv)triumph:python raizyr$ python virtualenv/bin/easy_install twisted

Revision history for this message
Carl Meyer (carljm) wrote :

Considering this a "wontfix" and not migrating to new tracker at https://github.com/pypa/virtualenv/issues - shebang lines can't include paths with spaces, it's unlikely this will ever change, and I don't see a reasonable way for virtualenv to work around this. Calling the scripts with the python binary is a reasonable end-user workaround.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.