ladybug-tools / lbt-grasshopper

:green_book: Collection of all Ladybug Tools plugins for Grasshopper
GNU Affero General Public License v3.0
55 stars 15 forks source link

Failure to write set_python_path.bat when home folder contains non-ASCII characters #1001

Closed coditect closed 1 year ago

coditect commented 3 years ago

The LBSetup component in installer.gh fails when it tries to create set_python_path.bat when it is run on Windows by a user whose home folder contains non-ASCII characters. The symptoms of this issue have been described on Discourse.

The problem can be resolved fairly easily by writing set_python_path.bat using UTF-8 instead of ASCII. The built-in open() function in write_iron_python_batch_file() would need to be replaced with io.open() so that an explicit character encoding could be specified, and a call to chcp would need to be added to the top of the batch file. The modified code would look something like this:

def write_iron_python_batch_file(python_exe):
    """Write a batch file to have Rhino search for libraries in ladybug_tools.

    Args:
        python_exe: The path to the Python executable to be used for installation.
    """
    # Get environement variables
    home_folder = os.getenv('HOME') or os.path.expanduser('~')
    directory = os.path.join(home_folder, 'ladybug_tools')
    working_drive = python_exe[:2]

    # Write the batch file to call the Python executable.
    batch = 'chcp 65001\n{}\n"{}" -m ladybug_rhino set-python-search\nPAUSE'.format(
        working_drive, python_exe)
    batch_file = os.path.join(directory, 'set_python_path.bat')
    with io.open(batch_file, 'w', encoding='utf-8') as outf:
        outf.write(batch)
    print('Writing set_python_path batch File to:\n{}\n '.format(batch_file))

It is important to note, however, that resolving this issue alone may not allow all users with non-ASCII home folder names to install Ladybug. Issue #1002 may apply as well.

chriswmackey commented 3 years ago

Thank you for the suggestion , @coditect . However, I can confirm that this is unfortunately not a complete solution. Even if we could install the software in a folder with Non-ASCII characters, the simulation engines (EnergyPlus and Radiance) do not support non-ASCII characters. So users installing to such a location will be unable to run simulations.

If you think it helps, I can add a check into the installer.gh for non-ASCII characters and give users an explicit warning that they need to create an account with a username containing only ASCII characters. Just let me know if you think this is better than the current failure message and I'll add it.

chriswmackey commented 1 year ago

This has all been addressed in LBT 1.5 and above. As long as the user installs with the Pollination Single-Click installer available here, they will be able to use the plugin while having any unicode character in their username.