Skip to content
This repository has been archived by the owner on Feb 25, 2018. It is now read-only.

Import error with pythonnet #116

Closed
maxslimmer opened this issue Dec 6, 2015 · 12 comments
Closed

Import error with pythonnet #116

maxslimmer opened this issue Dec 6, 2015 · 12 comments
Labels

Comments

@maxslimmer
Copy link

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
Copy link
Contributor

timeyyy commented Dec 7, 2015

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

@maxslimmer
Copy link
Author

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
Copy link
Contributor

timeyyy commented Dec 7, 2015

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

@maxslimmer
Copy link
Author

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
Copy link
Contributor

timeyyy commented Jan 24, 2016

@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
Copy link

jonasH commented Jan 29, 2016

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
Copy link
Author

@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
Copy link

jonasH commented Feb 1, 2016

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
Copy link
Contributor

timeyyy commented Feb 1, 2016

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
Copy link
Contributor

timeyyy commented Feb 1, 2016

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
Copy link

jonasH commented Feb 2, 2016

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

@den-run-ai
Copy link

See my answer on stack overflow:

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants