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

Ipyc not including json in standalone executable #1748

Open
JonahEMorgan opened this issue Nov 4, 2023 · 4 comments
Open

Ipyc not including json in standalone executable #1748

JonahEMorgan opened this issue Nov 4, 2023 · 4 comments
Labels

Comments

@JonahEMorgan
Copy link

Description

IronPython is not including the json module in a standalone executable when compiling one, resulting in an error message.

Steps to Reproduce

  1. Create a python script that imports json
  2. Compile using ipyc your-python-file.py /target:exe /standalone
  3. Run your-python-file.exe

Expected behavior:

Python script works

Actual behavior:

IronPython outputs this error message: Error occurred: No module named 'json'

Version Information

Microsoft Windows
Version 22H2 (OS Build 22621.2283)

IronPython 3.4.1 (3.4.1.1000)
[.NETFramework,Version=v4.6.2 on .NET Framework 4.8.9181.0 (64-bit)]

@slozier
Copy link
Contributor

slozier commented Nov 9, 2023

json is part of the standard library and would need to be included in the standalone assembly as well.

Similar issue for on ipy2: IronLanguages/ironpython2#759

@JonahEMorgan
Copy link
Author

I copied the python standard library in the IronPython "Lib" directory to a new subdirectory of my project titled "Lib" and I added

import sys
sys.path.append("Lib")

to my python code. This fixed the python import errors, but now I am receiving a new error message from .NET: "Error occurred: Could not load file or assembly 'System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. Invalid pointer (Exception from HRESULT: 0x80004003 (E_POINTER))"

@slozier slozier added the ipyc label Nov 19, 2023
@slozier
Copy link
Contributor

slozier commented Nov 19, 2023

Hmm, I'm not able to reproduce the error with a simple program. Although it looks like ipyc is only embedding System.Memory and System.Runtime.CompilerServices.Unsafe so if a code path is trying to use System.Buffers then I guess it makes sense that it would fail... As a workaround I think you can explicitly include the assembly on build:

ipyc your-python-file.py /target:exe /standalone "C:\Program Files\IronPython 3.4\System.Buffers.dll"

@JonahEMorgan
Copy link
Author

Adding the System.Buffers library allows the code to run. However, when the UDPServer in my code receives a packet, it throws this error:

Exception happened during processing of request from ('127.0.0.1', 55451)
Traceback (most recent call last):
  File "C:\Users\my-username\source\repos\python\thing\lib\socketserver.py", line 305, in _handle_request_noblock
Error occurred: Object reference not set to an instance of an object.

The weird thing is that this error does not happen when using the IronPython console to run my code.

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

No branches or pull requests

2 participants