Giter Site home page Giter Site logo

Comments (11)

XCanG avatar XCanG commented on August 24, 2024 1

Ok, I delete AHK_PATH variable and now everything is works without extra definition to path.

from ahk.

spyoungtech avatar spyoungtech commented on August 24, 2024

This is interesting. Thanks for providing the report and permission details @XCanG

I haven't been able to reproduce this on my local system running as admin or otherwise in either cmd or powershell. Our CI tests in AppVeyor also run as an administrator.

One possible key difference is that I usually install ahk and place the autohotkey executable in a virtualenv (e.g. in venv/Scripts) and let ahk discover the executable this way.

I'm still searching for answers on why this permission issue may happen. One possible reason would be a bug in how executable_path is being formed. For example, if somehow executable_path is a directory rather than the actual .exe, it would produce this Permission Denied error. There may be a bug there. If you are using the AHK_PATH env variable or specifying the path by keyword, be sure to use absolute path directly to the executable.

Could you tell me what the output is of

print(ahk.executable_path)

Also, try the following steps to setup an environment and see if you have different results....

mkdir test
cd test
py -3.7 -m venv venv
venv\Scripts\activate
python -m pip install ahk
copy D:\Prog\AutoHotkey\AutoHotkey.exe venv\Scripts

Then try running your script.

Also it would be good to know what version of Windows you are running and if you are in a domain environment or not. And, if possible, provide full code you have for instantiating ahk.

If none of the above works for you. I'm wondering if adding shell=True to the subprocess.Popen call would help your situation.

from ahk.

XCanG avatar XCanG commented on August 24, 2024
>>> print(ahk.executable_path)
D:\Prog\AutoHotkey\

Running script from virtulenv have same error.

Full code is test code from example:

from ahk import AHK
ahk = AHK()
ahk.mouse_position = (200, 200)

last line throw error...

Windows 10 x64 version 10.0.17134

from ahk.

spyoungtech avatar spyoungtech commented on August 24, 2024

Ok, this is interesting.

So, somehow, the lib is incorrectly detecting the executable_path.

D:\Prog\AutoHotkey\ should be D:\Prog\AutoHotkey\AutoHotkey.exe !

If you do the following, it should alleviate the problem.

ahk = AHK(executable_path='D:\\Prog\\AutoHotkey\\AutoHotkey.exe')

Let me know if that fixes things.

Meantime, I'll investigate why this is happening. Basically, if you set AHK_PATH, that is used... otherwise shutil.which is used to find the executable, which should be giving the full path, not just the directory.

from ahk.

XCanG avatar XCanG commented on August 24, 2024

Oh, yes, defining path to .exe helps, now script run without error.

from ahk.

XCanG avatar XCanG commented on August 24, 2024

In global environment variable Path have this path ...;D:\Prog\AutoHotkey\;... (not in user environment)
And I also have global AHK_PATH which is fully equal to:

D:\Prog\AutoHotkey\

from ahk.

spyoungtech avatar spyoungtech commented on August 24, 2024

Ah, so AHK_PATH should be the full path including the filename AutoHotkey.exe. Alternatively, if you simply make the AHK_PATH variable undefined, it should find the executable automagically.

Can you try removing that global AHK_PATH var and see if it works automatically?

If that works, I'll be sure to update the docs to make this more clear.

from ahk.

spyoungtech avatar spyoungtech commented on August 24, 2024

Glad that works. So the behavior is as expected, but this tells me that maybe the docs or interface needs some work.

Perhaps a better name for the AHK_PATH variable would be less confusing, since in PATH you just specify the directory... Alternatively, maybe we shouldn't use the variable at all.

from ahk.

XCanG avatar XCanG commented on August 24, 2024

I guess if you want to use AHK_PATH you make little check if it end to .exe otherwise you add os.path.join(AHK_PATH, "AutoHotkey.exe").

from ahk.

spyoungtech avatar spyoungtech commented on August 24, 2024

That's definitely a possible solution.

Technically, the executable can be named anything and the extension is not necessary or could even be something else entirely. For example, if someone really wanted the executable to be named C:\corp_auto_tool.bin and have that in AHK_PATH and expect it to work.

I think what I'd lean towards in a code-based approach to this would be to add a check and raise an error if this variable is mis-configured.
maybe something like

if os.path.isdir(executable_path):
    raise ValueError('AHK_PATH must be a file, not a directory')

Anyhow, I'll have to give this some more thought and will probably include a change in the next release.

Meanwhile, I'll update the docs, too.

If you'd like to make a PR against this, I'd happily review.

from ahk.

spyoungtech avatar spyoungtech commented on August 24, 2024

Marking this one as resolved and using #32 to track progress on action items for changes.

Feel free to reopen or pick up in 32 if you have more questions on this.

Thanks again for the report!

from ahk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.