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

Build and deploy Python wheels to PyPI #841

Merged
merged 16 commits into from Sep 10, 2017
Merged

Conversation

danielhers
Copy link
Collaborator

@danielhers danielhers commented Aug 31, 2017

  • Test on various architectures and Python versions
    (Build for macOS, test)
    (Build for Windows, test)
    (GPU version)

@danielhers
Copy link
Collaborator Author

Trying this in a separate repository: https://github.com/danielhers/dynet-manylinux1

@neubig
Copy link
Contributor

neubig commented Sep 2, 2017

I'm thinking about fixing the Python 2.0.1 version today. It's OK to fix it now then build the wheel files afterwards, right?

@danielhers
Copy link
Collaborator Author

danielhers commented Sep 2, 2017 via email

@danielhers
Copy link
Collaborator Author

Eventually I'd like to add a section to DyNet's .travis.yml to make it deploy to PyPI automatically whenever a tag is created.

@danielhers
Copy link
Collaborator Author

@neubig The automatic PyPI deployment (upon tag creation in clab/dynet) will require adding the PyPI username and (encrypted) password to .travis.yml. Do you want to use your or mine? To use yours, you can add the TWINE_USERNAME and TWINE_PASSWORD environment variables to the global environment in .travis.yml. The TWINE_PASSWORD variable should be encrypted in a clone of clab/dynet (not a fork).

@danielhers
Copy link
Collaborator Author

Regarding Windows and GPU, I don't know how to do that on Travis CI, so maybe we'll open another issue for that (in addition to #657, which I think can be closed once this is finished). I don't have access to a machine with a GPU and the ability to install Docker on (which I need for building the Linux wheels), but maybe they can be built on a machine with CUDA even if it doesn't have a GPU.

@danielhers danielhers changed the title [WIP] Build and deploy Python wheels to PyPI Build and deploy Python wheels to PyPI Sep 4, 2017
@danielhers
Copy link
Collaborator Author

danielhers commented Sep 5, 2017

Turns out march=native does pose a problem (the wheels are created successfully but may cause Illegal Instructions when run on a different machine), so I'm removing it from CMakeLists.txt using sed right before creating the wheel.

@danielhers
Copy link
Collaborator Author

The Linux wheels now work, at least on the machines I've tested them on. I'm not sure about the macOS wheels, though, as I don't have a Mac to try on. It looks like delocate doesn't actually put the shared library into the wheel, although auditwheel works. This might be the same problem as matthew-brett/delocate#15 - with DyNet it's a bit complicated but I think it's also just a Python file at the top rather than a package (there's no __init__.py). It might be necessary to change the structure a bit to make the wheels work on macOS too. Or maybe they work already, I don't know - it would be nice if someone tried them (pip install dynet==2.0.1.post5).

@neubig
Copy link
Contributor

neubig commented Sep 6, 2017

First, this is absolutely awesome that we will be able to install DyNet without compiling. I really appreciate this :)

That being said, it doesn't look like it works on Mac:

(dynet-throwaway) itachi:~ neubig$ python
Python 3.6.2 |Continuum Analytics, Inc.| (default, Jul 20 2017, 13:14:59) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import dynet
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/neubig/anaconda/envs/dynet-throwaway/lib/python3.6/site-packages/dynet.py", line 15, in <module>
    from _dynet import *
ImportError: dlopen(/Users/neubig/anaconda/envs/dynet-throwaway/lib/python3.6/site-packages/_dynet.cpython-36m-darwin.so, 2): Library not loaded: libdynet.dylib
  Referenced from: /Users/neubig/anaconda/envs/dynet-throwaway/lib/python3.6/site-packages/_dynet.cpython-36m-darwin.so
  Reason: image not found
>>> 

The work-around here doesn't seem to be working either, as it doesn't look like libdynet.dylib is installed at all #146

@danielhers
Copy link
Collaborator Author

Yes, #146 is just what I was afraid of; that delocate isn't really putting libdynet.dylib into the wheel. As I said in my previous comment, I think this has to do with the directory structure of the DyNet Python files, and the fact that they're not in a proper package.
Maybe we could use wheels for Linux and keep using the .tar.gz source distribution for macOS and Windows, and fix this in a future PR.
If you agree, I'll add a commit avoiding the wheel upload for osx. Please also let me know what you prefer regarding the twine (PyPI) credentials.

@danielhers
Copy link
Collaborator Author

For now I removed the macOS wheels from PyPI, so if your OS doesn't have a wheel, you'll just get the source distribution and compile it automatically.

@neubig
Copy link
Contributor

neubig commented Sep 6, 2017

If this might be working on Mac I can try it one more time.

@danielhers
Copy link
Collaborator Author

It's working, but precompiled wheels are just for Linux for now (for Mac you'll get the source distribution).

@danielhers
Copy link
Collaborator Author

So, I opened issues for the remaining tasks related to this, but I think the current PR is ready and useful:

  • Refactored .travis.yml to make it easier to modify and add parts.
  • Automatic deployment to PyPI on new tags in clab/dynet.
  • Precompiled wheels for Linux, tested in multiple architectures. Other OSs still get the sdist as before.
  • Groundwork for macOS precompiled wheels.

@neubig neubig merged commit 1590451 into clab:master Sep 10, 2017
@danielhers danielhers deleted the deploy branch September 10, 2017 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants