Closed jamesbraza closed 1 year ago
Did you restart the shell or even the pc after changing the value of the variable? Test it by getting the raw value out in the shell.
On Sat, 7 Jan 2023 at 01:02, James Braza @.***> wrote:
Here is what I have gathered to do, using PowerShell on Windows 10 Pro:
git clone @.***:iterativ/openopc2.git cd openopc2 pyenv local 3.10.9 python -m venv venv .\venv\Scripts\activate python -m pip install -e . "pyinstaller>=5.6.2,<6" pyinstaller --onefile --clean --noconfirm --paths ./openopc2
--hidden-import=json --hidden-import=win32timezone --hidden-import=pythoncom
--name OpenOpcService openopc2/gateway_service.py .\dist\OpenOpcService.exe debugWhy no poetry? I don't really like poetry for various reasons, mainly poetry shell is still a work-in-progress imo. I cargo-culted the pyinstaller line from here https://github.com/iterativ/openopc2/blob/3dc6a9522a3a5f30b243b4b8e44fb7409a2a1388/scripts/build_executables.ps1#L2 .
Windows user or system environment variables aren't getting seen by OpenOpcService.exe, what am I doing wrong?
[image: image] https://user-images.githubusercontent.com/8990777/211119247-9ddcde9d-26ab-488e-b7d2-e7d1e396095f.png
OpenOpcService Starting service on port 7766 Open Opc Config: OPC_HOST : localhost OPC_SERVER : Matrikon.OPC.Simulation OPC_CLIENT : OpenOPC OPC_GATEWAY_HOST : 192.168.0.115 OPC_GATEWAY_PORT : 7766 OPC_CLASS : Graybox.OPC.DAWrapper OPC_MODE : gateway OPC_TIMEOUT : 1000 Traceback (most recent call last): File "gateway_service.py", line 106, in
File "win32serviceutil.py", line 864, in HandleCommandLine File "win32serviceutil.py", line 653, in DebugService File "win32serviceutil.py", line 1119, in SvcRun File "gateway_service.py", line 52, in SvcDoRun File "gateway_server.py", line 101, in main File "Pyro5\server.py", line 237, in init File "Pyro5\svr_threads.py", line 124, in init File "Pyro5\socketutil.py", line 278, in create_socket OSError: [WinError 10049] The requested address is not valid in its context [2816] Failed to execute script 'gateway_service' due to unhandled exception! — Reply to this email directly, view it on GitHub https://github.com/iterativ/openopc2/issues/38, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACERAJJNNWBEO2JZ5L5BWZDWRCXADANCNFSM6AAAAAATTSKTLU . You are receiving this because you are subscribed to this thread.Message ID: @.***>
-- Lorenz Padberg Iterativ GmbH BrĂĽckfeldstrasse 16 3012 Bern Web: www.iterativ.ch
Tel: +41 (0)78 685 21 06 Mail: @.***
Okay I took a deeper look at this today. What I was doing was invoking .\dist\OpenOpcService.exe debug
using PowerShell, but adding the new environment variables with the PowerShell window still open.
Test it by getting the raw value out in the shell.
By doing this testing with os.environ
, I learned PowerShell requires a restart to intake new environment variables. This is actually documented behavior: Windows PowerShell Tip of the Week
One thing to watch out for: when we used SetEnvironmentVariable to create a new user- or machine-level environment variable that variable didn’t always show up when we ran this command in Windows PowerShell:
Get-ChildItem Env:
Or at least it didn’t show up until we restarted PowerShell. (Or started up a new instance of PowerShell.)
Okay so, if you add environment variables, make sure you close PowerShell/PyCharm/etc before kicking off OpenOpcService.exe
.
I also verified that both user and system environment variables will be read by OpenOpcService.exe
.
Case closed! Feel free to let me know if you have any follow up comments.
Here is what I have gathered to do, using PowerShell on Windows 10 Pro:
Why no
poetry
? I don't really likepoetry
for various reasons, mainlypoetry shell
is still a work-in-progress imo. I cargo-culted thepyinstaller
line from here.Windows user or system environment variables aren't getting seen by
OpenOpcService.exe
, what am I doing wrong?