Start a new topic
Answered

Dynamic folder interpreter path

Hello,

I've read here https://bit.ly/2lDbo9m that "Royal TSX (for macOS) uses standard macOS techniques to locate the executables automatically."


How can I override this? MacOS uses a legacy Python version (2.7) but my script uses a more modern Python 3 syntax.


I've already added an alias in my .bash_profile and checked the "Evaluate Bash Profile" option in settings but this doesn't help.


Thanks!

Matteo


Best Answer

Hi Matteo,


I was about to suggest the same approach as you, then tested it and basically encountered the same problem as you did.


The problem here is that we're using /usr/bin/env to locate python which doesn't consult your .bash_profile. It only tries to find python in your PATH.


Because we don't have any kind of preferences for dynamic folder script interpreters in Royal TSX at the moment, your only option is to ensure that python resolves to python3 in your PATH.

On my machine for instance I was able to make this work by creating a symlink named "python" that points to "python3" in its install directory at "/Library/Frameworks/Python.framework/Versions/3.6/bin". Here's the command I used to set this up: "sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python"


Since the python 3 install directory is the first entry in my PATH (before /usr/bin where python 2 is installed by default) "/usr/bin/env python" then actually resolves to "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3".


Of course, the various paths mentioned depend on your environment. Let me know if you have trouble setting this up. Happy to help!


cheers,

felix


Answer

Hi Matteo,


I was about to suggest the same approach as you, then tested it and basically encountered the same problem as you did.


The problem here is that we're using /usr/bin/env to locate python which doesn't consult your .bash_profile. It only tries to find python in your PATH.


Because we don't have any kind of preferences for dynamic folder script interpreters in Royal TSX at the moment, your only option is to ensure that python resolves to python3 in your PATH.

On my machine for instance I was able to make this work by creating a symlink named "python" that points to "python3" in its install directory at "/Library/Frameworks/Python.framework/Versions/3.6/bin". Here's the command I used to set this up: "sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/bin/python3 /Library/Frameworks/Python.framework/Versions/3.6/bin/python"


Since the python 3 install directory is the first entry in my PATH (before /usr/bin where python 2 is installed by default) "/usr/bin/env python" then actually resolves to "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3".


Of course, the various paths mentioned depend on your environment. Let me know if you have trouble setting this up. Happy to help!


cheers,

felix

Hi Felix,

thanks a lot for your suggestion.


I've been able to manage this in a different way: since the "PATH" order is significant, I've added this at the end of my .bash_profile:


alias python='/usr/local/bin/python3'

export PATH=/usr/local/opt/python/libexec/bin:$PATH


By doing this it works just fine (note that Python 3 have been installed with Homebrew).


Thanks again,

Matteo

Hi Matteo,


awesome - glad you got it working!


I like your approach too! It's worth mentioning for other users though that it requires enabling "Preferences - Dynamic Folder - Evaluate Bash Profile" to work.


We're thinking about implementing a way to let Royal TSX automatically detect if python3 is installed and if so, use it by modifying the shebang we insert to "/usr/bin/env python3". But if we can't detect python3 (using /usr/bin/env python3) we fall back to the previous shebang "/usr/bin/env python".

What do you think about that approach?


cheers,

felix

Hi Felix,

as a former Linux user, I always like to choose by myself. I think that the "magical" approach in which the application automatically detects the executable's path is nice, but it needs some kind of override, even in the settings or in a configuration file. By doing that the user will have the ability to fit the application for it's special case, like someone with python3 in it's machine but using a company-provided script that requires python2 or vice versa.


Anyway, thanks again for such a great product!


Regards,

Matteo

Hi Matteo,


thx for the feedback. Matches my thoughts exactly.

By default, Royal TSX should use the latest python version, but a setting under "Preferences - Dynamic Folder" should allow the user to select one of the following options:

  • Automatic (Latest) - Default
  • Python 3
  • Python 2 (or older)


cheers,

felix

Hi Matteo,


I'm happy to report that the option to switch between different versions of Python has been implemented in the current Royal TSX beta (4.1.3.3).

You'll find the option under "Preferences - Dynamic Folder - Python".


You can get the current beta here: https://www.royalapps.com/go/kb-ts-mac-downloadbeta


Please let me know if it works as expected!


cheers,

felix

Hi Felix,

wow, that fast!


I've just downloaded it but here the "auto" mode falls back to Python2, while putting it to Python3 makes it working.


FYI: 


$ which python

/usr/bin/python


$ which python3

/usr/local/bin/python3


Cheers,

Matteo

Hi Matteo,


our check basically does "/usr/bin/env python3 --version" and checks if a successful exit code is returned.

Could you please verify that this works on your system using a regular bash shell?


thx,

felix

Hi Felix,

that's strange! I've just tried again and I can confirm that if I set it on "Automatic" or "Python 2" it doesn't works (missing module). If I set it to "Python 3" it works fine.


$ /usr/bin/env python3 --version

Python 3.7.4


Cheers,

Matteo

Interesting!


Are you sure you're running this inside a default bash shell and not starting a custom shell before checking the python version?

To verify this, you could try starting bash manually from whatever shell you're in: "bash --login" and then checking the python version from there.


thx,

felix

Hi Felix,

same result.


matteo-mac:~ matteo$ bash --login

matteo-mac:~ matteo$ /usr/bin/env python3 --version

Python 3.7.4


I've also tried using a different user on my machine, a user that I never use:


matteo-mac:~ matteo$ su dummy

Password:

bash-3.2$ bash -login

matteo-mac:matteo dummy$ whoami

dummy

matteo-mac:matteo dummy$ /usr/bin/env python3 --version

Python 3.7.4


Hope this helps!


Cheers,

Matteo

Hmm, weird...

Do you have "Preferences - Dynamic Folder - Evaluate Bash Profile" enabled?

Hi Felix,

I've tried with another Mac and... it works fine! Somehow it's just this one, not a big deal!


Have a nice day!


Matteo

Login or Signup to post a comment