-
Notifications
You must be signed in to change notification settings - Fork 22
Running setup.py build in Windows in Admin prompt results in Access denied errors #12
Comments
Interesting, I haven't actually tried using this on windows yet but I'll give it a poke when I get home -- I'd start with trying to build the examples: https://github.com/asottile/setuptools-golang-examples and see what you run into |
I'll give that a shot. Thanks! Note that using "c-shared" option on go build is not available in Go 1.8 on Windows. Its slated for release in Go 1.9. That's why I had to build from source. |
Ah sorry. Not Go 1.9, should be Go 1.10: golang/go#11058 |
Ah, so the first error is actually the meaningful one, seems we probably need to extend this to include whatever link flag that works on windows (similar to #8) The second error is due to |
Ah OK! Thank you! Are you planning to put the patch in for the link flag or is that something you would like me to help with? |
If you'd like to take a stab at it feel free -- I'm not sure when I'll get to that (something something copious amounts of freetime 😆) -- the |
I put in the shutil fix, and also a fix for converting unicode strings in the env to normal strings: ellinorcrux@728e5f2 The unicode string thing might only be an issue in py27. I'm not sure what effect it would have in py3. The thing I'm confused about though is that it seems that the '-Wl,--unresolved-symbols=ignore-all' arguments are ignored completely. I am actually using gcc despite being on Windows. After my fix I now get the following output: |
heh yeah, I've hit the environ problem before as well -- they need to be "native" strings on windows ( So python for windows is usually compiled with msvc -- the error messages also look like msvc errors, I'm thinking we'll need to find the "allow undefined symbols" option for msvc. |
I'm pretty certain its using gcc. I tried using "/FORCE" from here: https://msdn.microsoft.com/en-us/library/70abkas3.aspx I'm not sure that MSVC is even supported for "--buildmode=c-shared" option yet, so I'm not sure there's any value in adding the equivalent flags in for it. |
hmmmm... I'll have to poke at this -- perhaps I'll be able to look into this more over the holiday weekend -- do you have some directions on how I can get started with building |
Here's the guide to building from source: https://golang.org/doc/install/source |
Note that some of the unit tests for the built-in libraries might fail when you install from source. This wasn't a problem for me because I wasn't planning to use those libraries for this project. The installation worked fine otherwise :) |
I played around with this a bit more. It appears the main issue is now the "undefined reference to __imp__Py..." errors. I noticed that one of the things that was getting included was "C:\Python27\PC". This folder actually doesn't exist in my installation. I've noticed it doesn't exist in a fresh installation on another machine either, so this doesn't seem quite right. I think the missing references are meant to be in a file called libpython27.a in the C:\Python27\libs folder, but adding "-IC:\Python27\libs" to CGO_CFLAGS didn't seem to help. Not sure what to try next... |
So the way python linking works is kind of odd. When it builds the |
I tried following the instructions in this article since it looks very promising, but it didn't help either: I ended up with "c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lpython27" I added the -L and -l flags to CGO_LDFLAGS. I'm not sure exactly what the gcc call will look like, and if I faithfully reproduced it. |
I understand what you're saying. Unfortunately I think MinGW doesn't support any such option for the linker: http://mingw.5.n7.nabble.com/ignoring-unresolved-symbols-in-shared-libraries-td14076.html because of some underlying Windows thing that I don't understand. However in the end I did manage to get this to work by adding "-LC:\Python27\libs -lpython27 " to CGO_LDFLAGS. I mentioned this earlier as not working; that's because I had a typo 🤦♀️ Thank you so much for your help and this awesome utility! 👍 I will submit some suggested changes in my fork of the repo soon once I've cleaned my stuff up a little. |
Cool! This is actually how this utility used to work before this change -- maybe we can conditionally enable that approach only on windows? |
Ah, interesting. I've uploaded some code that worked for me, but I wasn't even thinking about pypy when I wrote it. Here's what I've got: Feel free to use parts of it if you like, or rewrite it to better accommodate other platforms. |
Sounds good! We can probably hook up appveyor as well to keep this from breaking in the future -- cool to see that it wasn't far off from having windows just work! Thanks again for the investigation on this 👍 |
I tried applying (iteratively) the changes necessary to get the tests to pass, my progress is here Just wanted to confirm a few things about your setup before continuing as I'm getting into territory I don't fully understand :)
For me I have these setups:
I'm getting to the following: python2.7.14I'm currently getting to the following build error:
which seems to be fixable via this Adding that define, I can successfully build, but something seems not right with the shared objects created:
python3.6.3For whatever reason (?) I don't need to jump through the |
Another useful datapoint might be oh but I can see from your screenshot that'll just be |
To answer your questions, I'm using:
I believe there are some issues with Python 64 bit and MINGW64 which might explain the issues you're seeing. Firstly, the "__imp_Py_InitModule4" missing reference should be in a file called "libpython27.a" or "libpython35.a" in the PythonXY/libs folder. The 64 bit version of Python does not provide this library, apparently because the MINGW64 runtime interferes with the MSVC runtime. The Python on Windows binaries are compiled using MSVC. I could not find this well documented anywhere, but here's where I got this idea: https://stackoverflow.com/questions/7492416/building-64bit-libpython27-a-using-cygwin-dlltool (the second answer) also mentioned here: https://groups.google.com/forum/#!topic/cython-users/UX70kTr-6vk This thread also gives more insight into the whole conflict between Python and MINGW64: Pretty frustrating. From observing the discussion on the Golang side, it looks like they're not planning on supporting MSVC anytime soon, while the Python guys don't really have a supported solution either, despite the scientific Python community having a need for it. This appears to be the current workaround: http://ascend4.org/Setting_up_a_MinGW-w64_build_environment#Setup_Python_for_compilation_of_extensions |
ah ok, only supporting 32bit is fine for me for now -- I'll try again with 32bit In the meantime, can you try checking out my branch and running the tests and see if they pass? |
I'll definitely try running the tests. Thanks! |
tox_stdout.txt |
Nice, the other error is due to the ca file being not findable -- need to re-remember which environment variable enables that and |
Hey did you manage to get the unit tests working? Let me know if you want me to run them again on my machine. I know its kind of a hassle to set the environment up. Thanks for looking into this :) |
oh shoot, lost this in my long list of TODOs, I'm leaving this email unread and I'll take a look this weekend. Thanks for the patience and for helping double check the work :) |
Hoooray!!!!
now to work out the tox environment variable and then try and hook it up with CI! |
Try it out! Just released v1.2.0 |
Awesome thanks again! |
Hi,
I tried using this tool in an elevated command prompt, but I got some strange "Access is denied" and "undefined reference to f" errors. See image:
If I go to the location of my "root" file, I'm able to build using the go build command in the image above.
I'm on Python 2.7.11, 32 bit on Windows 8
I built Go from source, and I'm on git hash 8f70e1f8a91db6c8a1bcc292766af95e52e8512b
I have gcc installed in MINGW32
This is what my setup.py looks like:

There are a ton of other arguments I didn't include. I have a template for setup.py that I generate for each package I make.
I'm wondering what the best approach to trying to debug this issue is. I've tried looking at the files its complaining about, but I can't find all of them. Any tips?
Thanks!
The text was updated successfully, but these errors were encountered: