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

Does it support the type like "unsigned char *"? #99

Open
hideinhat opened this issue Aug 16, 2023 · 8 comments
Open

Does it support the type like "unsigned char *"? #99

hideinhat opened this issue Aug 16, 2023 · 8 comments
Labels

Comments

@hideinhat
Copy link

Hi, Thank you for your awesome work.
I have a question, does it support the type like "unsigned char *" , I test in ctypes, "unsigned char *" can be indicated as "ctypes.POINTER(ctypes.c_ubyte)" ,is that the same in zugbruecke?

@s-m-e
Copy link
Member

s-m-e commented Aug 16, 2023

Basically zugbruecke is identical to ctypes most of the time, i.e. a "drop-in replacement". In some cases, additional directives might be required for Memory Synchronization.

@s-m-e s-m-e added the question label Aug 16, 2023
@hideinhat
Copy link
Author

Basically zugbruecke is identical to ctypes most of the time, i.e. a "drop-in replacement". In some cases, additional directives might be required for Memory Synchronization.

Thank you for timely reply.
I installed zugbruecke and wine. But when I run wenv init , an error happend:
wenv init wine: configuration in L"/home/admin/anaconda3/envs/py38/share/wenv/win32" has been updated. Traceback (most recent call last): File "/home/admin/anaconda3/envs/py38/lib/python3.8/urllib/request.py", line 1354, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/home/admin/anaconda3/envs/py38/lib/python3.8/http/client.py", line 1256, in request self._send_request(method, url, body, headers, encode_chunked) File "/home/admin/anaconda3/envs/py38/lib/python3.8/http/client.py", line 1302, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/home/admin/anaconda3/envs/py38/lib/python3.8/http/client.py", line 1251, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/home/admin/anaconda3/envs/py38/lib/python3.8/http/client.py", line 1011, in _send_output self.send(msg) File "/home/admin/anaconda3/envs/py38/lib/python3.8/http/client.py", line 951, in send self.connect() File "/home/admin/anaconda3/envs/py38/lib/python3.8/http/client.py", line 1418, in connect super().connect() File "/home/admin/anaconda3/envs/py38/lib/python3.8/http/client.py", line 922, in connect self.sock = self._create_connection( File "/home/admin/anaconda3/envs/py38/lib/python3.8/socket.py", line 808, in create_connection raise err File "/home/admin/anaconda3/envs/py38/lib/python3.8/socket.py", line 796, in create_connection sock.connect(sa) ConnectionRefusedError: [Errno 111] Connection refused
Could you please help to fix this error?

@s-m-e
Copy link
Member

s-m-e commented Aug 17, 2023

What happens if you simply run wenv --help and wenv python --version on the command line (with your py38 environment activated)?

@hideinhat
Copy link
Author

What happens if you simply run wenv --help and wenv python --version on the command line (with your py38 environment activated)?

I run wenv --help and wenv python --version on the command line, it shows the following message:

(py38) admin@idcgpu1:$ wenv --help
wenv 0.5.1 - the Wine Python environment

  • wenv cache: fetches installation files and caches them for offline usage (Python interpreter, pip, setuptools, wheel)
  • wenv clean: removes current environment (Python interpreter, pip, setuptools, wheel, all installed packages)
  • wenv help: prints this help text
  • wenv init: sets up an environment (Wine prefix, Python interpreter, pip, setuptools, wheel)
  • wenv init_coverage: enables coverage analysis inside wenv
  • wenv version: shows wenv's version (also available as --version)

The following interpreters, scripts and modules are installed and available:

  • wenv python
  • wenv pythonw
    (py38) admin@idcgpu1:$ wenv python --version
    Python 3.7.4
    (py38) admin@idcgpu1:/data$ python
    Python 3.8.12 (default, Oct 12 2021, 13:49:34)
    [GCC 7.5.0] :: Anaconda, Inc. on linux
    Type "help", "copyright", "credits" or "license" for more information.

The version of Python in wenv is 3.7.4, which is not match with Python in my py38 environment.
I googled ConnectionRefusedError: [Errno 111] Connection refused, some suggests to check host and port which is listening on, but I don't know which host and port are used by the server and client.
It is also said that the connection may be blocked by a firewall.
I have no idea how to troubleshoot this problem.

@s-m-e
Copy link
Member

s-m-e commented Aug 17, 2023

Ok, wenv works as expected, which also means that Wine is working. That's a good start.

The version of Python in wenv is 3.7.4, which is not match with Python in my py38 environment.

This is expected.

[... ] some suggests to check host and port which is listening on, but I don't know which host and port are used by the server and client.
It is also said that the connection may be blocked by a firewall.

zugbruecke has two components: The Unix Python interpreter, running on your Linux system, acting as a client, and a Windows Python interpreter, running on Wine, acting as the server (plus a second connection in reverse, but that's not causing the failure in your case). The host is localhost, i.e. your machine. There is no connection to the outside world. The (two) ports are chosen more or less at random, see here and here. For debugging, you could theoretically overwrite the calls to get_free_port and set those values to integers of your choice. Make sure they are free ports and greater than 1024. It's unlikely a firewall issue though it can be, so checking its configuration might be worth it, too.

Besides, you can set the version of the Windows Python interpreter to something more recent, say a 3.8 or 3.9, via the pythonversion parameter, see here. Sometimes this does the trick.

For further debugging: What Linux distribution/version is this (lsb_release -a)? All flavours of Fedora/CentOS/RedHat and older versions of Debian/Ubuntu (predating 2018) are known to cause issues.

What version of Wine (wine --version)? Distribution packages are known to cause issues - packages from the Wine project directly usually work better.

@hideinhat
Copy link
Author

Thanks a lot for your response.
At first, I run wenv clean then overwrite the calls to get_free_port according to your instructions and set port values to integers as 5400,5405.

[...]
# from .lib import get_free_port
from .typeguard import typechecked
import socket

# WINE PYTHON INTERPRETER CLASS

@typechecked
def get_free_port() -> int:

    s = socket.socket()
    s.bind(("", 5405))
    port = s.getsockname()[1]
    s.close()

    return port

@typechecked
class Interpreter(InterpreterABC):
[...]

It still shows that error above when I run wenv init.
And I'm going to set the version of the Windows Python interpreter,find the following code in two places (~/anaconda3/envs/py38/lib/python3.8/site-packages/zugbruecke/core/config.py and ~/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/config.py),

if key == "pythonversion":
            return PythonVersion(self['arch'], 3, 7, 4, 'stable')  # Define Wine-Python version

I modified PythonVersion(self['arch'], 3, 8, 12, 'stable') which is in ~/anaconda3/envs/py38/lib/python3.8/site-packages/zugbruecke/core/config.py, then run wenv init and wenv python --version, the ConnectionRefusedError is still there and the version of the Windows Python interpreter also does not change to 3.8.12.
then I also modified PythonVersion(self['arch'], 3, 8, 12, 'stable') which is in ~/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/config.py, after I run wenv init and wenv --help, another error happend and Windows Python interpreters is not installed.

(py38) admin@idcgpu1:~$ wenv init
wine: configuration in L"/home/admin/anaconda3/envs/py38/share/wenv/win32" has been updated.
Traceback (most recent call last):
  File "/home/admin/anaconda3/envs/py38/bin/wenv", line 8, in <module>
    sys.exit(cli())
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/env.py", line 764, in cli
    Env().cli()
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/env.py", line 708, in cli
    self._cli_dict[cmd]()
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/env.py", line 617, in _cli_init
    self.ensure()
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/env.py", line 262, in ensure
    self.setup_pythonprefix()
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/env.py", line 431, in setup_pythonprefix
    archive_zip.write(self._get_python(self._p["offline"]))
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/env.py", line 338, in _get_python
    return download(self._p["pythonversion"].as_url(), mode="binary")
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/site-packages/wenv/_core/source.py", line 49, in download
    with urlopen(httprequest) as response:
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/home/admin/anaconda3/envs/py38/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
(py38) admin@idcgpu1:~$ wenv --help
wenv 0.5.1 - the Wine Python environment

- wenv cache: fetches installation files and caches them for offline usage (Python interpreter, pip, setuptools, wheel)
- wenv clean: removes current environment (Python interpreter, pip, setuptools, wheel, all installed packages)
- wenv help: prints this help text
- wenv init: sets up an environment (Wine prefix, Python interpreter, pip, setuptools, wheel)
- wenv init_coverage: enables coverage analysis inside wenv
- wenv version: shows wenv's version (also available as `--version`)

The following interpreters, scripts and modules are installed and available:

(None)

there is Linux version and Wine version:

(py38) admin@idcgpu1:~$ wine --version
wine-8.13
(py38) admin@idcgpu1:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal

Thank you for your patience.

@s-m-e
Copy link
Member

s-m-e commented Aug 18, 2023

It still shows that error above when I run wenv init.

I misread you initial issue - it looked very similar to something that I had seen before many times due to the lack of formatting, but it is different.

wenv fails to connect to the internet (!) to collect the Python interpreter itself, which causes wenv init to fail. Either it's a connectivity issue or, more likely, you are trying to use a version that is unavailable as a "Windows embeddable package" as required by wenv and zugbruecke. The last point release of Python 3.8 for which this is available is 3.8.10, see here. Subsequent releases are missing those builds, see here.

pythonversion is actually a configurable parameter in zugbruecke (other than the ports). You can set it as a configuration parameter. If you want to go for 3.8, set it to 3.8.10 (stable).

@hideinhat
Copy link
Author

Thank you for responsing.
I tried to change the version of Python to 3.8.10 in conda environment and set pythonversion by ZUGBRUECKE_PYTHONVERSION=3.8.10.
ConnectionRefusedError still there.
I run wenv python --version, it returns Python 3.7.4.
Is that the right way to set pythonversion?

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