Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shell script doesn't work for python paths with spaces #514

Closed
sqlalchemy-bot opened this issue Oct 24, 2018 · 7 comments
Closed

shell script doesn't work for python paths with spaces #514

sqlalchemy-bot opened this issue Oct 24, 2018 · 7 comments
Labels

Comments

@sqlalchemy-bot
Copy link

Migrated issue, originally created by Nonprofit Metrics

Upon installing Alembic into a Python Virtualenv, where a space exists in the python path, the "alembic" shell command fails with the message "bad interpreter: No such file or directory". I'm using alembic 1.0.1, just installed from pip.

It appears the error is from the shebang line in the script (...bin/alembic), which for me reads:

#!"/Users/me/Directory With Spaces/myvirtualenv/bin/python2.7"

No way of escaping the path or spaces works at all. The way I got it to work is to replace the shebang line with:

#!/bin/sh
'''exec' "/Users/me/Directory With Spaces/myvirtualenv/bin/python2.7" "$0" "$@"
' '''

This is the way celery and others solve the problem.

I couldn't figure out where setup.py generated the shell "bin/alembic" file, or else I would've submitted a pull request.

Thanks!

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

I need detail on "this is the way celery solves the problem", because this behavior is not on the alembic side, it's part of pip. see pypa/pip#923 . are you on a very old version of pip?

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

it looks like the hack you are looking for is already implemented in pip, at least version 18 here has it:

$ mkdir "I Have Spaces"
[classic@photon2 tmp]$ cd I\ Have\ Spaces/
[classic@photon2 I Have Spaces]$ virtualenv .myvenv
Using real prefix '/opt/python-3.7.0'
New python executable in /home/classic/tmp/I Have Spaces/.myvenv/bin/python3.7
Also creating executable in /home/classic/tmp/I Have Spaces/.myvenv/bin/python
Installing setuptools, pip, wheel...done.
[classic@photon2 I Have Spaces]$ .myvenv/bin/pip install alembic
Collecting alembic
  Downloading https://files.pythonhosted.org/packages/1a/37/8df0e37d730f096f5a41514823eaec3c5e169510a5c5ddc3dcbab5446ee8/alembic-1.0.1.tar.gz (1.0MB)
    100% |████████████████████████████████| 1.0MB 1.7MB/s 

    ... more packages installed ...

[classic@photon2 I Have Spaces]$ ./.myvenv/bin/alembic init foo
  Creating directory /home/classic/tmp/I Have Spaces/foo ... done
  Creating directory /home/classic/tmp/I Have Spaces/foo/versions ... done
  Generating /home/classic/tmp/I Have Spaces/foo/README ... done
  Generating /home/classic/tmp/I Have Spaces/foo/script.py.mako ... done
  Generating /home/classic/tmp/I Have Spaces/alembic.ini ... done
  Generating /home/classic/tmp/I Have Spaces/foo/env.py ... done
  Please edit configuration/connection/logging settings in '/home/classic/tmp/I Have Spaces/alembic.ini' before proceeding.


here's the file, with the "exec" you are looking for:

[classic@photon2 I Have Spaces]$ head -5 .myvenv/bin/alembic 
#!/bin/sh
'''exec' "/home/classic/tmp/I Have Spaces/.myvenv/bin/python3.7" "$0" "$@"
' '''
# -*- coding: utf-8 -*-
import re

so make sure you're on a recent version of pip

@sqlalchemy-bot
Copy link
Author

Nonprofit Metrics wrote:

I'm using pip 18.1, the current version of pip. I just reinstalled alembic, and I'm still getting this version of the shell file:

#!"/Users/me/Directory With Spaces/myvirtualenv/bin/python2.7"
# EASY-INSTALL-ENTRY-SCRIPT: 'alembic==1.0.1','console_scripts','alembic'
__requires__ = 'alembic==1.0.1'
import re
import sys
from pkg_resources import load_entry_point

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(
        load_entry_point('alembic==1.0.1', 'console_scripts', 'alembic')()
    )

I'll update virtualenv, create a fresh virtualenv, and double-check. Perhaps is a python 2.7 thing.

@sqlalchemy-bot
Copy link
Author

Michael Bayer (@zzzeek) wrote:

works in python 2.7:

[classic@photon2 I Have Spaces]$ virtualenv-2.7 .myvenv
New python executable in /home/classic/tmp/I Have Spaces/.myvenv/bin/python2
Also creating executable in /home/classic/tmp/I Have Spaces/.myvenv/bin/python
Installing setuptools, pip, wheel...done.
[classic@photon2 I Have Spaces]$ .myvenv/bin/pip install alembic
Collecting alembic

...

Successfully installed Mako-1.0.7 MarkupSafe-1.0 SQLAlchemy-1.2.12 alembic-1.0.1 python-dateutil-2.7.3 python-editor-1.0.3 six-1.11.0
[classic@photon2 I Have Spaces]$ head -5 .myvenv/bin/alembic 
#!/bin/sh
'''exec' "/home/classic/tmp/I Have Spaces/.myvenv/bin/python2" "$0" "$@"
' '''
# -*- coding: utf-8 -*-
import re

@sqlalchemy-bot
Copy link
Author

Nonprofit Metrics wrote:

I was unable to reproduce when I created a new Virtualenv just now. I set this Virtualenv up a few years ago, so even though I have the current version of pip, something must be going on there. Apologies about the issue -- should I mark it as resolved, or can you delete it on your end?

@sqlalchemy-bot
Copy link
Author

Nonprofit Metrics wrote:

Made sure that pip and virtualenv were up-to-date before install alembic

@sqlalchemy-bot
Copy link
Author

Changes by Nonprofit Metrics:

  • changed status to closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant