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

Compile On Windows #100

Closed
reaperhulk opened this issue Aug 5, 2014 · 37 comments
Closed

Compile On Windows #100

reaperhulk opened this issue Aug 5, 2014 · 37 comments

Comments

@reaperhulk
Copy link
Member

Right now pynacl won't compile on windows. We should fix that!

@dstufft
Copy link
Member

dstufft commented Aug 5, 2014

It might if you install msys and mingw :V

@dstufft
Copy link
Member

dstufft commented Aug 5, 2014

But yea we should.

Realstically it should build using distutils build_clib instead of shelling out to configure and make... but it was doing something broken that I don't remember and I didn't feel like figuring it out.

@inigo-montoya
Copy link

I'm having issues getting pynacl to compile on windows as well.
...
copying src\nacl_lib\crypto_scalarmult.h -> build\lib.win32-2.7\nacl_lib
copying src\nacl_lib\crypto_secretbox.h -> build\lib.win32-2.7\nacl_lib
copying src\nacl_lib\crypto_sign.h -> build\lib.win32-2.7\nacl_lib
copying src\nacl_lib\randombytes.h -> build\lib.win32-2.7\nacl_lib

running build_clib
error: [Error 193] %1 is not a valid Win32 application

Cleaning up...
Removing temporary dir c:\users\admini1\appdata\local\temp\pip_build_Administrator...
Command C:\Python27\python.exe -c "import setuptools, tokenize;file='c:\users\admini
1\appdata\local\temp\pip_build_Administrator\PyNaCl\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record c:\users\admini1\appdata\local\temp\pip-trsgx2-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\admini1\appdata\local\temp\pip_build_Administrator\PyNaCl
Exception information:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
File "C:\Python27\lib\site-packages\pip\commands\install.py", line 283, in run
requirement_set.install(install_options, global_options, root=options.root_path)
File "C:\Python27\lib\site-packages\pip\req.py", line 1435, in install
requirement.install(install_options, global_options, _args, *_kwargs)
File "C:\Python27\lib\site-packages\pip\req.py", line 706, in install
cwd=self.source_dir, filter_stdout=self._filter_install, show_stdout=False)
File "C:\Python27\lib\site-packages\pip\util.py", line 697, in call_subprocess
% (command_desc, proc.returncode, cwd))
InstallationError: Command C:\Python27\python.exe -c "import setuptools, tokenize;file='c:\users\admini1\appdata\local\temp\pip_build_Administrator\PyNaCl\setup.py';exec(compile(getattr(tokenize, 'open', open)(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record c:\users\admini1\appdata\local\temp\pip-trsgx2-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\admini~1\appdata\local\temp\pip_build_Administrator\PyNaCl

@inigo-montoya
Copy link

realized msys wasn't installed just mingw...will keep you posted

@reaperhulk
Copy link
Member Author

The current pynacl expects to be able to run a shell script, so Windows is (unfortunately) unsupported. If you're working on fixing that, great!

@inigo-montoya
Copy link

keep you posted if I get to it and I'll file a PR if/when it's done.

*Joshua Lederman | *Gem
Director of Product
1410 Abbot Kinney Blvd, Penthouse 2 Venice, CA 90291
Joshua@gem.co joshua@gem.co | Gem.co https://gem.co/ |
(424)-291-1198

On Wed, Dec 3, 2014 at 6:25 PM, Paul Kehrer notifications@github.com
wrote:

The current pynacl expects to be able to run a shell script, so Windows is
(unfortunately) unsupported. If you're working on fixing that, great!


Reply to this email directly or view it on GitHub
#100 (comment).

@Insoleet
Copy link

I almost managed to build pynacl on windows.

Using the prebuilt binaries of libsodium :
https://download.libsodium.org/libsodium/releases/

And using the environment variable :
SET SODIUM_INSTALL system

I manage to build pynacl with VC++ 2010 and python 3.3

I just have one last problem :

running install_egg_info
running egg_info
[..]
File "C:\Python33\lib\distutils\util.py", line 125, in convert_path
raise ValueError("path '%s' cannot be absolute" % pathname)
ValueError: path '/Users/dstufft/projects/pynacl/src/libsodium/AUTHORS' cannot b
e absolute

EDIT : Fixed by cloning the git locally and removing the inclusion of libsodium in the MANIFEST file.
But now, I still cannot use the library :

from nacl.signing import SigningKey
[...]
Traceback (most recent call last):
File "", line 1, in
File "C:\Python33\lib\site-packages\nacl\signing.py", line 20, in
import nacl.c
File "C:\Python33\lib\site-packages\nacl\c__init__.py", line 17, in
from nacl.c.crypto_box import (
File "C:\Python33\lib\site-packages\nacl\c\crypto_box.py", line 24, in <module

crypto_box_SECRETKEYBYTES = lib.crypto_box_secretkeybytes()

File "C:\Python33\lib\site-packages\nacl_lib__init__.py", line 71, in geta
ttr

self._lib = self.ffi.verifier.load_library()
File "C:\Python33\lib\site-packages\cffi\verifier.py", line 75, in load_librar
y
return self._load_library()
File "C:\Python33\lib\site-packages\cffi\verifier.py", line 151, in _load_libr
ary
return self._vengine.load_library()
File "C:\Python33\lib\site-packages\cffi\vengine_cpy.py", line 149, in load_li
brary
raise ffiplatform.VerificationError(error)
cffi.ffiplatform.VerificationError: importing 'C:\Python33\lib\site-packages
\nacl_lib_cffi__xb3560ebdxfb751af7.pyd': DLL load failed: Le module spécifié
est introuvable.

@cbrunker
Copy link

Working Build

The last entry on this issue was very close, just needed to use something like Dependency Walker on the .pyd file to find out what was missing.

Quick and dirty build instructions for Windows 32bit and Python 3.4.2 are below, this is using Visual Studio 2010 Express, and PyNaCl git snapshot as of 12th Jan 2015.

Test was successfully completed in a Windows 8.1 64bit environment.

Attempts were made using Mingw, however Mingw does not play nicely with cffi it seems.

Setup

  • Edit MANIFEST.in and remove SODIUM references
  • (Optional) Remove packaged sodium source
  • Download pre-built libraries for libsodium and Visual Studio
  • Install Visual Studio Express 2010 (which python 3.4 is built against)
  • Run cmd.exe and change directory to your PyNaCl source directory

Build

  • Tell the build script to use pre-built libs
    • set SODIUM_INSTALL=system
  • Let cl.exe and link.exe (Visual studio) know where the header and prebuilt libs are
    • set INCLUDE=C:\path\to\libsodium-1.0.1-msv\include
    • set LIB=C:\path\to\libsodium-1.0.1-msvc\Win32\Release\v100\dynamic
  • Rename dynamic lib names to 'sodium' instead of 'libsodium'
  • Build the code
    • C:\Python34\python.exe setup.py build
  • Install the code
    • C:\Python34\python.exe setup.py install

Last Step

The missing step:

  • Copy libsodium.dll from the dynamic directory (not the renamed sodium.dll) to the installed site package location's nacl_lib directory. Example location:
    • C:\Python34\Lib\site-packages\PyNaCl-0.3.0-py3.4-win32.egg\nacl_lib

@hoffmabc
Copy link

@cbrunker were you really able to get the code working with this process? I have tried replicating it several times now and it still bombs trying to call sub modules (i.e. import nacl.signing).

@hoffmabc
Copy link

@Insoleet did you get past this issue? I get the same one.

@Insoleet
Copy link

I don't use pynacl anymore because of this problem. I use "libnacl" now. https://libnacl.readthedocs.org/en/latest/

@hoffmabc
Copy link

Ok I was able to get that to work. I guess I have to port stuff over to libnacl now.

@cbrunker
Copy link

windows-pynacl
@hoffmabc Yes, I have used pynacl for cross platform (Win/Linux) libsodium support for multiple projects now. The initial setup for windows is a pain, however the library works without issue on windows and python 3.4.3

@hoffmabc
Copy link

Wow I'm still getting the missing module error. I followed your instructions to a T As well.

@reaperhulk
Copy link
Member Author

If someone wants to tackle the project to support this seamlessly we're happy to take a patch. The main challenge will really just be untangling the POSIX expectations for the SODIUM_INSTALL=bundled case.

One we have it working properly we can do a new release (and I'll be happy to build Windows wheels with static linking like we do for pyca/cryptography).

@hoffmabc
Copy link

Ok I would love to help on this so I'll see if @cpacia and I can make this happen.

@hoffmabc
Copy link

Oh @cbrunker just noticed you used python 3.4. Is it possible to build against python 2.7?

@cbrunker
Copy link

Haven't tried, you'll need to use VS2008 or similar for 2.7 instead of VS2010

@hoffmabc
Copy link

I got it to work. Once I have a proper instruction set I'll post a link.

@hoffmabc
Copy link

I've gotten this to work also as an egg zip file as long as you have the Visual C Redistributable installed it works fine.

@sheilatron
Copy link

Hi @hoffmabc , do you have instructions on building this for Python 2.7?

@sheilatron
Copy link

tackle the project to support this seamlessly we're happy to take a patch

@reaperhulk has anyone taken this up?

@hoffmabc
Copy link

Sorry I will post tomorrow

@reaperhulk
Copy link
Member Author

@sheilatron thus far no one has taken on the work to contribute a branch that builds on Windows. PyCA has infrastructure to do windows CI (and to produce and upload windows wheels) if someone contributes the patch, but most of my focus is on https://github.com/pyca/cryptography for now.

It sounds like perhaps @hoffmabc's instructions could be used to create the necessary PR though!

@cpacia
Copy link

cpacia commented Dec 23, 2015

We've been able to get it working on windows for OpenBazaar. Brian can provide detailed instructions. What are the chances of another release sometime soon? I'd like to use the key conversions in OB.

@reaperhulk
Copy link
Member Author

@warner what do you think of trying to do a release in the next few weeks? The accumulated last several months + windows support + the work you were reviewing the other night + the cffi 1.0 conversion (which I need to spend some time on) seems release worthy to me.

@hoffmabc
Copy link

+1

@warner
Copy link
Member

warner commented Dec 23, 2015

+1. I'm travelling a bunch in the next two weeks but I'll try to find some time to look at the current PRs.

@hoffmabc
Copy link

So I've been trying hard to recode this for Windows, but unfortunately I've realized it still will require a compiler like mingw or Visual C++ and I'm still running into some issues with it finding the dll.

Here are the instructions to work around it if you want to try them. I will continue working on a code submission though.

https://github.com/OpenBazaar/OpenBazaar-Server/wiki/Installing-pynacl-on-Windows

@hoffmabc
Copy link

I think the best approach would be to provide a wheel for users to install.

@sheilatron
Copy link

Thanks @hoffmabc ! We'll try out the instructions.

@reaperhulk
Copy link
Member Author

I went ahead and implemented Windows support. The necessary env flags are now in master and I started documenting it in #165. The next release of pynacl (hopefully next week) will ship windows wheels by default for python 2.7, 3.3, 3.4, and 3.5 on both 32-bit and 64-bit python.

@sheilatron
Copy link

Awesome! Thanks so much!

@hoffmabc
Copy link

👍

@reaperhulk
Copy link
Member Author

PyNaCl 1.0.1 ships with wheels for Windows (and OS X) now. 2.7, 3.3, 3.4, and 3.5 supported (and both 32-bit and 64-bit on the Windows side). Future releases will always ship this way. If you run into any problems please open a new issue! ✨

@AraHaan
Copy link

AraHaan commented Jul 17, 2016

I am having issues building this with Python 3.6 Alpha 3. It works on python 3.5 however. I get this:

Collecting PyNacl
  Using cached PyNaCl-1.0.1.tar.gz
Requirement already up-to-date: six in e:\users\elsword\desktop\python36-x86\lib
\site-packages (from PyNacl)
Requirement already up-to-date: cffi>=1.1.0 in e:\users\elsword\desktop\python36
-x86\lib\site-packages (from PyNacl)
Requirement already up-to-date: pycparser in e:\users\elsword\desktop\python36-x
86\lib\site-packages (from cffi>=1.1.0->PyNacl)
Installing collected packages: PyNacl
  Running setup.py install for PyNacl ... error
    Complete output from command E:\Users\Elsword\Desktop\python36-x86\python.ex
e -u -c "import setuptools, tokenize;__file__='E:\\Users\\Elsword\\AppData\\Loca
l\\Temp\\pip-build-druf4in4\\PyNacl\\setup.py';exec(compile(getattr(tokenize, 'o
pen', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install
--record E:\Users\Elsword\AppData\Local\Temp\pip-xcnmx096-record\install-record.
txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.6
    creating build\lib.win32-3.6\nacl
    copying src\nacl\encoding.py -> build\lib.win32-3.6\nacl
    copying src\nacl\exceptions.py -> build\lib.win32-3.6\nacl
    copying src\nacl\hash.py -> build\lib.win32-3.6\nacl
    copying src\nacl\public.py -> build\lib.win32-3.6\nacl
    copying src\nacl\secret.py -> build\lib.win32-3.6\nacl
    copying src\nacl\signing.py -> build\lib.win32-3.6\nacl
    copying src\nacl\utils.py -> build\lib.win32-3.6\nacl
    copying src\nacl\__init__.py -> build\lib.win32-3.6\nacl
    creating build\lib.win32-3.6\nacl\bindings
    copying src\nacl\bindings\crypto_box.py -> build\lib.win32-3.6\nacl\bindings

    copying src\nacl\bindings\crypto_hash.py -> build\lib.win32-3.6\nacl\binding
s
    copying src\nacl\bindings\crypto_scalarmult.py -> build\lib.win32-3.6\nacl\b
indings
    copying src\nacl\bindings\crypto_secretbox.py -> build\lib.win32-3.6\nacl\bi
ndings
    copying src\nacl\bindings\crypto_sign.py -> build\lib.win32-3.6\nacl\binding
s
    copying src\nacl\bindings\randombytes.py -> build\lib.win32-3.6\nacl\binding
s
    copying src\nacl\bindings\sodium_core.py -> build\lib.win32-3.6\nacl\binding
s
    copying src\nacl\bindings\__init__.py -> build\lib.win32-3.6\nacl\bindings
    running build_clib
    error: [WinError 193] %1 is not a valid Win32 application

    ----------------------------------------
Command "E:\Users\Elsword\Desktop\python36-x86\python.exe -u -c "import setuptoo
ls, tokenize;__file__='E:\\Users\\Elsword\\AppData\\Local\\Temp\\pip-build-druf4
in4\\PyNacl\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).re
ad().replace('\r\n', '\n'), __file__, 'exec'))" install --record E:\Users\Elswor
d\AppData\Local\Temp\pip-xcnmx096-record\install-record.txt --single-version-ext
ernally-managed --compile" failed with error code 1 in E:\Users\Elsword\AppData\
Local\Temp\pip-build-druf4in4\PyNacl\

@AraHaan
Copy link

AraHaan commented Jul 17, 2016

The reason why I need this is for the pyd's themself I do have the 1.0.1 for 3.5 but the Pyd's will not work on 3.6 Alpha 3 due to it only being able to read

{module name}.cp{python version}-{win32 or amd64}.pyd

And so yeah I need this to be able to embed these pyd's in a zip for 3.6 alpha as I perfer the embed versions mostly. (I can generate them myself due to make_zip.py that is only in the python source code.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

10 participants