问题
My local git/virtualenv is using pip
version 1.3.1. When I try to push my Python 3.3.2 app to Heroku, I get
Downloading/unpacking distribute==0.6.34 (from -r requirements.txt (line 5))
Running setup.py egg_info for package distribute
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "./setuptools/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "./setuptools/extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "./setuptools/dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "./setuptools/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "./setuptools/extension.py", line 5, in <module>
from setuptools.dist import _get_unpatched
File "./setuptools/dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-u58345/distribute
Storing complete log in /app/.pip/pip.log
! Push rejected, failed to compile Python app
Given I can't manually install distribute
on Heroku's servers, how am I supposed to avoid this bug?
回答1:
The behaviour you are seeing is an issue with pip itself: https://github.com/pypa/pip/issues/650
It seems that pip uses distribute to upgrade distribute.
However, what you need to do to fix your error is remove distribute from requirements.txt altogether. It's already there since it's being installed by the buildpack and there's no need to install it again using pip.
I believe you actually CAN and ARE installing distribute on heroku's servers via the default buildpack. Heroku's Python support is implemented in the form of a buildpack. You can read more about buildpacks here.
If you wish to have a specific version of distribute, in this case one without the pip-bug, you have to replace it's source within the buildpack your app is using. It can be done like so:
- Get the original buildpack from heroku at https://github.com/heroku/heroku-buildpack-python
- In your cloned buildpack (at the time of this writing) you will find
/vendor/distribute-0.6.36
. This is the problem. Replace it with a newer version of distribute. Inside the buildpack's
bin/compile
script, replace the version of distribute the buildpack is using. In my case this was replacing line 31DISTRIBUTE_VERSION="0.6.36"
withDISTRIBUTE_VERSION="0.6.45"
Upload your buildpack to github and tell heroku to use it by saying
$ heroku config:set BUILDPACK_URL=https://github.com/you/name-of-buildpack-python-repo.git
ALTERNATIVELY
Tell heroku to use my custom buildpack instead of the original. My builbpack's only differences to the original are those described in steps 1-4.
To override the buildpack for an existing application:
$ heroku config:set BUILDPACK_URL=https://github.com/jhnwsk/heroku-buildpack-python.git
Or if you are creating a new application
$ heroku create myapp --buildpack https://github.com/jhnwsk/heroku-buildpack-python.git
When you push your application to Heroku after making these changes you should see something like
-----> Fetching custom git buildpack... done
-----> Python app detected
-----> No runtime.txt provided; assuming python-2.7.4.
-----> Preparing Python runtime (python-2.7.4)
-----> Installing Distribute (0.6.45)
-----> Installing Pip (1.3.1)
which means you have your custom distribute version running.
来源:https://stackoverflow.com/questions/16931105/heroku-push-rejected-due-to-pip-distribute-bug-whats-the-workaround