Hal and python3.

More
7 years 4 days ago #148979 by dab77
Hal and python3. was created by dab77
Hi, I've read some dicussion on the python3 porting of linuxcnc, and I understand it is not going to happen soon.
I'm writing a Python GUI to interface with HAL only, and I'm doing it with python2.7, because python3 is not importing hal module.
But now and then I'm looking at how to do it, because soon or later I want to (have to) use python3.

Hal, alone, should be simple to port to python3, and I would like to help in this, but I'm not the Master, so I'm hitting my first wall..
when importing (in python3) the resulting error is:
Code:
dab@dab-lcnc-vm:/usr/lib/python3.5/dist-packages$ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import hal Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python3.5/dist-packages/hal.py", line 34, in <module> import _hal ImportError: No module named '_hal' >>>
as you can see I'm into python3.5/dist-packages folder. I have created that on the base of python2.7 folder where hal.py and _hal.i386-linux-gnu.so are located. The only thing I've modified into hal.py is declaring:
Code:
#!/usr/bin/env python3
at the beginning.
The problem is that I really don't know why _hal module is not found at all..
obviously if doing 'import hal' from python2 consolle it import it without problems.

Do you have some hint about it?
Since I cannot find _hal.i386-linux-gnu.so into the source code on github, my question is: is it created at compile time, during installation? what source is it compiled from?

Thanks, Davide.

Please Log in or Create an account to join the conversation.

More
7 years 3 days ago #149011 by cmorley
Replied by cmorley on topic Hal and python3.
There has been a few attemps for python3 in linuxcnc.
I myself added an experimental branch that uses cython to add python3 HAL to linuxcnc.

There was a post today about another attempt:
github.com/LinuxCNC/linuxcnc/issues/403#issuecomment-547125870

I have never seen a file named: _hal.i386-linux-gnu.so
it should be _hal.so and be in lib/python (in a RIP project)

Chris

Please Log in or Create an account to join the conversation.

More
7 years 3 days ago - 7 years 3 days ago #149042 by dab77
Replied by dab77 on topic Hal and python3.

cmorley wrote: I have never seen a file named: _hal.i386-linux-gnu.so
it should be _hal.so and be in lib/python (in a RIP project)

Chris

I'm working on a virtualized copy of my working system, which is last 2.9 installed in Debian Stretch. to be honest I don't remember if I downloaded an already cooked iso (probably) or if I installed kernel and lcnc on my own, but there's no _hal.so and no /lib/python folder at all!
Code:
dab@dab-lcnc-vm:~$ uname -a Linux dab-lcnc-vm 4.9.0-9-rt-686-pae #1 SMP PREEMPT RT Debian 4.9.168-1+deb9u5 (2019-08-11) i686 GNU/Linux dab@dab-lcnc-vm:~$ sudo locate _hal.i386 /usr/lib/python2.7/dist-packages/_hal.i386-linux-gnu.so /usr/lib/python3/dist-packages/_hal.i386-linux-gnu.so dab@dab-lcnc-vm:~$ sudo locate _hal.so dab@dab-lcnc-vm:~$
and I'm sure that using python2 the _hal module used is that in: /usr/lib/python2.7/dist-packages/_hal.i386-linux-gnu.so , because if I change its name, importing hal fails.
Last edit: 7 years 3 days ago by dab77.

Please Log in or Create an account to join the conversation.

More
7 years 3 days ago #149051 by cmorley
Replied by cmorley on topic Hal and python3.
Fair enough - I never use installed versions so it seemed weird to me.

Chris

Please Log in or Create an account to join the conversation.

More
6 years 11 months ago #150861 by dab77
Replied by dab77 on topic Hal and python3.
Hi, I started to follow this github issue thread ( Python 2 EOL Roadmap? ) and I ended up in installing Debian Buster on a VM and compiled dgarr/py3 branch as RIP. No big issues to install. the Buster I downloaded was the '10.2 amd64 net install' iso, and python 2.7 was the default version, so I had to 'update-alternatives' to set python 3.7 as the default version.
I can report that importing hal works with python3, but since I've built the code as run-in-place, I had to add:
Code:
sys.path.append('/home/dab/linuxcnc/lib/python/')
prior to import hal.

another issue with rip is that when closing the window, I have to call
Code:
halrun -U
and I'm doing that with:
Code:
halrun_U = "/home/dab/linuxcnc/scripts/halrun -U" os.system(halrun_U)
because the system command 'halrun -U' is not recognized. Maybe I can solve that by adding that folder to the list of executable folders..

Anyway, it seems to me that a lot of good work has already been done on that branch, as I've tried also Axis and it seems to work (in sim mode), and as python 2 has to be left behind, I think this should be one of the main lcnc developers targets. As far as I can I'll help with this too.

Thanks, Davide.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

More
6 years 11 months ago - 6 years 11 months ago #150863 by dgarrett
Replied by dgarrett on topic Hal and python3.

another issue with rip is that when closing the window, I have to call


With a RIP build, you must source the rip-environment
script in *every* shell attempting to run LinuxCNC, or
halrun, or any other LinuxCNC-specific scripts or
executables. The script is also needed to set
environmental variables for locating scripting language
modules/libraries.

The script establishes the correct environmental
variables for:
1) PATH (used for locating executables)
2) PYTHONPATH (for locating python modules)
3) TCLLIBPATH (for locating tcl libraries)
4) etc.

Example session (on buster testing dgarr/py3):
Code:
$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 10 (buster) Release: 10 Codename: buster $ which python /usr/bin/python $ python --version Python 3.7.3 $ python Python 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import hal Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'hal' >>> $ $ # fix by sourcing rip-environment in your linuxcnc-dev directory: $ $ source /home/git/linuxcnc-dev/scripts/rip-environment $ python Python 3.7.3 (default, Apr 3 2019, 05:39:12) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import hal >>> dir(hal) ['HAL_BIT', 'HAL_FLOAT', 'HAL_IN', 'HAL_IO', 'HAL_OUT', 'HAL_RO', 'HAL_RW', 'HAL_S32', 'HAL_U32', 'MSG_ALL', 'MSG_DBG', 'MSG_ERR', 'MSG_INFO', 'MSG_NONE', 'MSG_WARN', 'Param', 'Pin', '_ItemWrap', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_hal', 'component', 'component_exists', 'component_is_ready', 'connect', 'error', 'get_msg_level', 'get_value', 'is_kernelspace', 'is_rt', 'is_sim', 'is_userspace', 'item', 'new_sig', 'pin_has_writer', 'sampler_base', 'set_msg_level', 'set_p', 'stream', 'streamer_base'] >>>


NOTE: If a system has both RIP build and a deb install, things can
get *very* confusing if you are not careful. I usually uninstall
LinuxCNC debs when testing RIP builds.
Last edit: 6 years 11 months ago by dgarrett.
The following user(s) said Thank You: tommylight

Please Log in or Create an account to join the conversation.

Time to create page: 0.260 seconds
Powered by Kunena Forum