1

On a fresh mac OS X(tried both Maverick and Yosemite), I am getting strange results from pythons pip.

I have installed a new version of python in /usr/local/bin/python, and the original version of python still lives at /usr/bin/python. My installation of python is set as the default.

which python
/usr/local/bin/python

When installing my python module, pip installs all the dependencies to /usr/local/bin/python which is correct. However, it adds the she-bang line of /usr/bin/python to the console scripts.

Now when I use my console script, I get an import error, because the dependencies don't exist in that version of python.

I can fix this by hand by editing the she-bang line

#!/usr/local/bin/python

and all is fine.

So, here is my question. Why is this happening? Why is pip installing all the dependencies to one version, and using the she-bang from a different version?

More important question, how can I prevent this from happening, so anyone else who installs my module doesn't have to go change this line themselves?


Here is my setup.py:

import sys

from setuptools import setup, find_packages

import foobar

requires = ['pyyaml==3.11',
            'six==1.8.0',
            'cement==2.4',
            'setuptools>=7.0',
            'python-dateutil>=2.2',
            ]

setup_options = dict(
    name='foobar',
    version=foobar.__version__,
    description='Command Line Interface.',
    long_description=open('README.rst').read(),
    author='Humdinger',
    url='example.com',
    packages=find_packages('.', exclude=['tests*', 'docs*']),
    package_dir={'foobar': 'foobar'},
    install_requires=requires,
    classifiers=(
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Intended Audience :: System Administrators',
        'Natural Language :: English',
        'Programming Language :: Python',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.3',
        'Programming Language :: Python :: 3.4',
    ),
    entry_points={
        'console_scripts': [
            'foo=foobar.foo:main'
        ]
    }
)

setup(**setup_options)

Upon suggestion, I have added the line

#!/usr/bin/env python 

to my setup.py and foo.py file.

This does not seem to solve the problem.


I have also tried to re-try on a fresh mac OSX without installing my own version of python.

$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python

$ pip --version
pip 1.5.6 from /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg (python 2.7)

$ head -1 $(which pip)
#!/usr/bin/python

$ head -1 $(which eb)
#!/usr/bin/python
Nick Humrich
  • 14,905
  • 8
  • 62
  • 85

1 Answers1

0

Edit, updating after comment with useful info.

Based on your comment, the pip you are using is executing /usr/bin/python per its shebang line, so that's why setuptools is replacing your shebangs with /usr/bin/python. You need to install pip using your new python, each version of python needs its own pip.

/usr/local/bin/python get-pip.py

However, you should really use virtualenv instead.

Community
  • 1
  • 1
ErlVolton
  • 6,714
  • 2
  • 15
  • 26
  • So your saying the she-bang lines should point the the version of python I want? What if the location differs on different computers? – Nick Humrich Oct 28 '14 at 20:10
  • it doesn't matter what they point to, it could be `#!/not/a/real/python`. As long as it's a shebang line that ends in "python", setuptools will replace it for you (during installation of the package) to point to the current python interpreter. – ErlVolton Oct 28 '14 at 20:11
  • Doesnt work, I tried adding `/usr/bin/env python` (Also tried `/usr/local/bin/python` ) and when I install it, the script still points to `/usr/bin/python` – Nick Humrich Oct 28 '14 at 20:57
  • Did you add `/usr/bin/env python` or `#!/usr/bin/env python` ? – ErlVolton Oct 28 '14 at 21:06
  • `#!/usr/bin/env python` – Nick Humrich Oct 28 '14 at 21:08
  • Can you show us `pip --version` and `head -1 $(which pip)` – ErlVolton Oct 28 '14 at 21:08
  • Might be onto something: `$ head -1 $(which pip)` is `#!/usr/bin/python` – Nick Humrich Oct 28 '14 at 21:18
  • I installed pip after installing the new python. I installed it using `python easy_install pip` and `which python` was correct. Pip even installs all dependencies into the correct python. Why would the she-bang line still be different? – Nick Humrich Oct 28 '14 at 21:24
  • Because the pip you installed with `python easy_install pip` is not the same pip you are executing when you just run `pip`. – ErlVolton Oct 28 '14 at 21:27
  • Ok that makes sense, but why would dependencies be installed into the right version of python? – Nick Humrich Oct 28 '14 at 21:28
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63811/discussion-between-erlvolton-and-humdinger). – ErlVolton Oct 28 '14 at 21:30