pynacl icon indicating copy to clipboard operation
pynacl copied to clipboard

Document Compiling On Windows

Open reaperhulk opened this issue 8 years ago • 6 comments

Okay, so here's how I have it building against Windows with the changes in #164:

  • Grab the latest libsodium-msvc release from downloads.libsodium.org
  • Unzip it and put it some place like C:\libsodium
  • Grab http://msinttypes.googlecode.com/svn/trunk/stdint.h and put that in C:\libsodium\include (this is required for Python 2.7 but not other releases)
  • The MSVC release zip from libsodium does not have a 64-bit VS2010 release, so to link against Python 64-bit 2.7 (which is technically built against VS2008 but links just fine against the VS2010 static libs) you need to check out the libsodium git source https://github.com/jedisct1/libsodium, check out the latest release tag, then open the vcxproj file for VS2010 (it's in builds/msvc/vs2010/libsodium), set the target to static release, then build it. You can then use the resulting .lib to statically link.

With those prerequisites out of the way you can then do something like this to build:

@set SODIUM_INSTALL=system
@set PYNACL_SODIUM_STATIC=1
@set LIB="C:\libsodium\path\to\static\lib\you\need";%LIB%
@set INCLUDE="C:\libsodium\include";%INCLUDE%
pip install .

(The PYNACL_SODIUM_STATIC flag is required if you want to link against the static libraries, but not if you want to use dynamic. If you use dynamic you'll need to drop the .lib file in the appropriate place post-install though and building a wheel will be a more involved process)

The next release of pynacl will ship static windows wheels by default so this is only necessary for users who don't want to wait or want to develop this project on windows.

reaperhulk avatar Jan 09 '16 18:01 reaperhulk

What about compile on VS2015 update 3 For Python 3.5 & 3.6?

AraHaan avatar Jul 17 '16 08:07 AraHaan

@AraHaan Has update 3 changed something? The above instructions will work just fine for VS2015 + Python 3.5, but we also do this for you via binary wheels so if you just run the latest pip pip install pynacl won't even require a compiler on Windows. The exception at the moment is for Python 3.6 since it's not out yet.

reaperhulk avatar Jul 17 '16 12:07 reaperhulk

Ah, I see from your other issue that 3.6 is your need. To compile it manually on 3.6 you'll need to grab the latest release: https://github.com/jedisct1/libsodium/releases and then compile it from the vcxproj file in the root of the unzipped dir.

reaperhulk avatar Jul 17 '16 12:07 reaperhulk

Also the lib on the current solution of theirs can be used if you do the DLL build as well (both would be the same just the other does not produce a DLL with it)

AraHaan avatar Jul 17 '16 14:07 AraHaan

I tried to get this working on MSYS2

In setup.py this

if not which("make"):
            raise Exception("ERROR: The 'make' utility is missing from PATH")

can not work on MSYS2. make is make.exe, so even if it is in path, searching for make will not find anything.

if we remove that, there is another error.

$ pip3 install .
Processing c:/msys64/home/philipp/pynacl
Requirement already satisfied: six in c:/msys64/mingw32/lib/python3.6/site-packages (from PyNaCl==1.3.0.dev1)
Requirement already satisfied: cffi>=1.4.1 in c:/msys64/mingw32/lib/python3.6/site-packages (from PyNaCl==1.3.0.dev1)
Requirement already satisfied: pycparser in c:/msys64/mingw32/lib/python3.6/site-packages (from cffi>=1.4.1->PyNaCl==1.3.0.dev1)
Installing collected packages: PyNaCl
  Running setup.py install for PyNaCl ... error
    Complete output from command C:/msys64/mingw32/bin/python3.exe -u -c "import setuptools, tokenize;__file__='C:/Users/Philipp/AppData/Local/Temp/pip-w_nkqv4b-build/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:/Users/Philipp/AppData/Local/Temp/pip-vqjv5p9r-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build/lib.mingw-3.6
    creating build/lib.mingw-3.6/nacl
    copying src/nacl/encoding.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/exceptions.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/hash.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/hashlib.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/public.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/secret.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/signing.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/utils.py -> build/lib.mingw-3.6/nacl
    copying src/nacl/__init__.py -> build/lib.mingw-3.6/nacl
    creating build/lib.mingw-3.6/nacl/pwhash
    copying src/nacl/pwhash/argon2i.py -> build/lib.mingw-3.6/nacl/pwhash
    copying src/nacl/pwhash/argon2id.py -> build/lib.mingw-3.6/nacl/pwhash
    copying src/nacl/pwhash/scrypt.py -> build/lib.mingw-3.6/nacl/pwhash
    copying src/nacl/pwhash/_argon2.py -> build/lib.mingw-3.6/nacl/pwhash
    copying src/nacl/pwhash/__init__.py -> build/lib.mingw-3.6/nacl/pwhash
    creating build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_aead.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_box.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_generichash.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_hash.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_kx.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_pwhash.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_scalarmult.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_secretbox.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_shorthash.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/crypto_sign.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/randombytes.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/sodium_core.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/utils.py -> build/lib.mingw-3.6/nacl/bindings
    copying src/nacl/bindings/__init__.py -> build/lib.mingw-3.6/nacl/bindings
    running build_clib
    error: [WinError 193] %1 ist keine zul▒ssige Win32-Anwendung

This ticket is 2 years old, still no way to build this lib in MSYS2 env

this project is in the same domain as pyopenssl and cryptography, which are both bigger projects and just build fine on MSYS2. Can we not get someone over here to take a look at this?

lovetox avatar Mar 28 '18 23:03 lovetox

I was build pynacl on Windows10 and VS2012 build process is success , but can't import from python.

cd PyNacl-1.2.1

set INCLUDE=%INCLUDE%;"C:/Program Files/Autodesk/Maya2017/include/python2.7";"E:/libsodium-1.0.15-msvc/include"
set LIB=%LIB%;"C:/Program Files/Autodesk/Maya2017/lib";"E:/libsodium-1.0.15-msvc/x64/Release/v110/dynamic"
set SODIUM_INSTALL=system

"C:/Program Files/Autodesk/Maya2017/bin/mayapy.exe" setup.py build install
Python 2.7.11 (default, Dec 21 2015, 22:48:54) [MSC v.1700 64 bit (AMD64)] on win32    
Type "help", "copyright", "credits" or "license" for more information.                 
>>> import nacl._sodium                                                                
Traceback (most recent call last):                                                     
  File "<stdin>", line 1, in <module>                                                  
ImportError: DLL load failed:                                         
>>>                                                                                    

zclongpop123 avatar Aug 15 '18 11:08 zclongpop123