cloudmatrix / esky

an auto-update framework for frozen python apps
BSD 3-Clause "New" or "Revised" License
363 stars 74 forks source link

Import error with pythonnet #116

Closed maxslimmer closed 8 years ago

maxslimmer commented 8 years ago

Getting ImportError: No module named site

when importing clr module from pythonnet. Freezing with py2exe without esky is creating a running executable. Only get this error when building as esky and then running the executable from bootstrap exe. If I run the exe in the version directory everything works.

timeyyy commented 8 years ago

Hi maxslimmer, are you using esky from pypi? Are you using python 2 or python3?

maxslimmer commented 8 years ago

Sorry, here's my environment: CPython 2.7.10 Same behavior with esky 0.9.8 and 0.9.9 (yes from pypi) pythonnet 2.1.0.dev1 py2exe 0.6.9 pywin32 219 Windows 7

If there's anything else I can do please let me know. I'm happy to do as much legwork as I can, but when I started looking into the bootstrapping code (where I suspect the problem is) I got pretty lost.

timeyyy commented 8 years ago

can i suggest to try the github master branch (i believe py2exe is working on that for python2)

maxslimmer commented 8 years ago

Just tried with 0.9.10.dev0. No dice. To be clear, the problem only happens when I have this line in my source: import clr

and I launch the app from the bootrapping exe in the appdir. otherwise esky + py2exe is working perfectly for me.

timeyyy commented 8 years ago

@maxslimmer sorry this is taking a while to come through. The bootstrap is showing a few issues for py2exe, Is changing over to cxfreeze an option? We are fully tested on running with cxfreeze. I will put some effort into py2exe after my exams in march.

jonasH commented 8 years ago

Hi! If I package just an import of clr and copy the Python.Runtime.dll into the folder in appdata I get the same import error. I use cxfreeze, is there a specific version that you have tested with? The exe down in the appdata folder works as expected.

I'm running: CPython 2.7.10 pythonnet 2.1.0-dev1 esky from github(29th jan) cx-Freeze 4.3.4 Windows 7

maxslimmer commented 8 years ago

@timeyyy I looked into cxfreeze a while back and decided not to go with it for reasons I can't recall. It sounds like @jonasH might be having the same problem with cxfreeze anyway. For the time being I've found alternatives to using clr/pythonnet. The library I wanted to reference was also provided as a COM server so I'm using pywin32 to access it and was able to re-implement the network protocol of another library function using pure python. Long story short: this issue is moot for me until I need something else from .Net that I can't or won't re-implement. I'm still happy to test when and if there is something to test.

jonasH commented 8 years ago

For me implementing the c# stuff is not an option, I will go with just freezing for now. If you need any help let me know.

timeyyy commented 8 years ago

I'm a fairly green programmer and i'm still learning the esky codebase so i cannot really delegate or tell you guys how you can help. If you want to get on board with a task take a look at the road map, some task are quite project independent such as setting up travis for osx

timeyyy commented 8 years ago

Anyway as a workaround until the patch is ready you can do this to get up and running with clr using cxfreeze,

data_path = os.path.join(sys.exec_prefix, 'Lib')
bscode = "_chainload = _orig_chainload\nbootstrap()"

setup(
    data_files=[('', [os.path.join(data_path, 'site-packages', 'Python.Runtime.dll')]), ],
    options = {"bdist_esky": {
                "freezer_module":"cxfreeze",
                           "bootstrap_code":bscode
jonasH commented 8 years ago

Thank you that worked out fine by settings the bootstrap_code option.

den-run-ai commented 7 years ago

See my answer on stack overflow:

https://stackoverflow.com/a/42778574/2230844