@@ -125,6 +125,72 @@ If you want to use a specific version of Python instead of the default,
125
125
you can change the Python version by setting the ` PYTHON ` environment variable
126
126
to the path of the ` python ` executable.
127
127
128
+ ### Deploying on Heroku
129
+
130
+ Heroku's default version of Python is not compiled with the ` --enabled-shared `
131
+ option and can't be accessed by PyCall. Alternative [ buildpacks] ( https://devcenter.heroku.com/articles/buildpacks ) are available,
132
+ including these that have been reported to work with PyCall:
133
+
134
+ https://github.com/richgong/heroku-buildpack-python
135
+ https://github.com/dsounded/heroku-buildpack-python
136
+ https://github.com/ReforgeHQ/heroku-buildpack-python
137
+
138
+ These community-developed buildpacks are not supported by Heroku, so it's
139
+ worth examining the source to make sure the buildpack you use suits your
140
+ needs. For instance, 'ReforgeHQ' works well with Python 3.8.1, but has not
141
+ been configured to work with other versions and may not be as generally
142
+ useful as the 'dsounded' or 'richgong' buildpacks.
143
+
144
+ The buildpack will expect to find both a ` runtime.txt ` and a ` requirements.txt `
145
+ file in the root of your project. You will need to add these to specify the
146
+ version of Python and any packages to be installed via ` pip ` , _ e.g_ to use
147
+ version Python 3.8.1 and version 2.5 of the 'networkx' package:
148
+
149
+ $ echo "python-3.8.1" >> runtime.txt
150
+ $ echo "networkx==2.5" >> requirements.txt
151
+
152
+ Commit these two files into project's repository. You'll use these to manage
153
+ your Python environment in much the same way you use the ` Gemfile ` to manage
154
+ Ruby.
155
+
156
+ Heroku normally detects which buildpacks to use, but you will want to override
157
+ this behavior. It's probably best to clear out existing buildpacks and specify
158
+ exactly which buildpacks from scratch.
159
+
160
+ First, take stock of your existing buildpacks:
161
+
162
+ $ heroku buildpack [-a YOUR_APP_NAME]
163
+
164
+ For a Ruby/Rails application this will typically report the stock ` heroku/ruby `
165
+ buildpack, or possibly both ` heroku/ruby ` and ` heroku/nodejs ` .
166
+
167
+ Clear the list and progressively add back your buildpacks, starting with the Python
168
+ community-developed buildpack. For example, if ` ruby ` and ` nodejs ` buildpacks were
169
+ previously installed, and chosing the 'ReforgeHQ' buildback, your setup process will
170
+ be similar to this:
171
+
172
+ $ heroku buildpacks:clear
173
+ $ heroku buildpacks:add https://github.com/ReforgeHQ/heroku-buildpack-python -i 1
174
+ $ heroku buildpacks:add heroku/nodejs -i 2
175
+ # heroku buildpacks:add heroku/ruby -i 3
176
+
177
+ If you have multiple applications on Heroku you will need to append each of these
178
+ with application's identifier (_ e.g._ ` heroku buildpacks:clear -a YOUR_APP_NAME ` ).
179
+
180
+ With each buildpack we are registering its index (the ` -i ` switch) in order to
181
+ specify the order Heroku will load runtimes and execute bootstrapping code. It's
182
+ important for the Python environment to be engaged first, as PyCall will need to
183
+ be able to find it when Ruby-based processes start.
184
+
185
+ Once you have set up your buildpacks, and have commited both ` requirements.txt ` and
186
+ ` runtime.txt ` files to git, deploy your Heroku application as your normally would.
187
+ The Python bootstrapping process will appear in the log first, followed by the Ruby
188
+ and so on. PyCall should now be able to successfully call Python functions from
189
+ within the Heroku environment.
190
+
191
+ NB It is also possible to specify buildpacks within Docker images on Heroku.
192
+ See Heroku's [ documentation on using Docker Images] ( https://devcenter.heroku.com/articles/build-docker-images-heroku-yml ) .
193
+
128
194
## Development
129
195
130
196
After checking out the repo, run ` bin/setup ` to install dependencies.
0 commit comments