Python configuration: Difference between revisions

From Eigenvector Research Documentation Wiki
Jump to navigation Jump to search
 
(29 intermediate revisions by 3 users not shown)
Line 1: Line 1:
===Purpose===
===Purpose===
Gives access to methods from popular packages in Python. Applicable for PLS_Toolbox/Solo 9.0.
Creates a Python virtual environment for PLS_Toolbox, giving access to evrimodel objects that use Python. Applicable for PLS_Toolbox/Solo 9.0 and newer.
The correct version of Python, and its necessary packages, will be installed or built for you.
 
===Synopsis===
 
:result  = config_pyenv(options);
 
===Options===
 
''options'' =  a structure array with the following fields:
 
* '''source''': [ {'conda'} | 'archived' ], The source of which Python is built and configured for PLS_Toolbox/Solo. When source='conda', a virtual environment is built using Miniconda/Anaconda. If source='archived', then the Python comes from an archived file. This file is available upon request to our helpdesk starting in 9.1.
 
* '''silent''': [ {'no'} | 'yes' ], Governs the level of user-input needed. A dialog box is created asking the user if they would like to continue with the configuration when silent='no'. No dialog box is created when silent='yes'.
 


===Methods Required for Configuration===
===Methods Required for Configuration===
Blow shows a table of the PLS_Toolbox methods that use Python. The table also shows the corresponding Python package used to run each method. Without the proper configuration, access is denied to all of these methods.  
Below shows a table of the PLS_Toolbox methods that use Python. The table also shows the corresponding Python package used to run each method. Without the proper configuration, access is denied to all of these methods.  
{| class="wikitable"
{| class="wikitable"
! PLS_Toolbox Method || Python Package  
! PLS_Toolbox Method || Python Package  
Line 16: Line 30:
|}
|}


===What's needed===
* Miniconda3
** This is a Python virtual environment management software. The management software is what's used to help manage, build, and maintain the PLS_Toolbox virtual environment. This software is free and take up less than 100 MB of space. Instructions to download and install are located below.
* MATLAB R2020b or higher
** This requirement allows the use of the most recent versions of Python and its packages.


Note: The configuration can take a couple of minutes to complete. The PLS_Toolbox virtual environment can take 1-2GB of space.
<b>Important Note: Python in PLS_Toolbox/Solo for Apple Silicon devices is not fully supported yet. </b>
 
===Conda Solution===
Used when <code>options.source='conda'</code>. This is the default method when running <code>config_pyenv</code>. Follow the steps below to create your virtual environment via Miniconda/Anaconda.
 
 
====What's needed====
* Either one of Miniconda3 or Anaconda3 (The ability to use Anaconda with PLS_Toolbox is for versions 9.1 and newer)
** Both of these are Python virtual environment management softwares. The management software is what's used to help build and maintain the PLS_Toolbox virtual environment. Instructions to download and install are located below. Miniconda3 is an abbreviated version of Anaconda3 that takes less space but does not have a user interface. Anaconda3 contains more packages and includes a nice interface for interaction, but takes much more space. We recommend Miniconda3 if you are new to either of these softwares. See this link to decide which is best for you: https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html#anaconda-or-miniconda. '''If you already have either of these, ensure that it has been added to the System Path for the configuration in MATLAB/Solo to work correctly.
* MATLAB R2020b or newer/ Solo 9.0 or newer
** This requirement allows the use of recent versions of Python and its packages.
* Internet connection for Miniconda3/Anaconda3 download and Python configuration
 
Note: The configuration can take a couple of minutes to complete. The PLS_Toolbox virtual environment can take between 1-2 GB of space.


A Python virtual environment is a setup denoting the version of Python being used as well as the packages and their versions. Virtual environments are created to organize these setups, and usually are created on a project-to-project basis. This PLS_Toolbox virtual environment is tailored for the user to use the Python methods in the toolbox. '''It is advised to not modify, add, or delete packages from this environment. We cannot guarantee that the software will work after modifications.'''
A Python virtual environment is a setup denoting the version of Python being used as well as the packages and their versions. Virtual environments are created to organize these setups, and usually are created on a project-to-project basis. This PLS_Toolbox virtual environment is tailored for the user to use the Python methods in the toolbox. '''It is advised to not modify, add, or delete packages from this environment. We cannot guarantee that the software will work after modifications.'''


===How to configure===
====How to configure====
Configuration requires that Miniconda3 be properly downloaded and installed following these instructions. Deviation from these instructions can lead to issues when running the configuration or running the Python methods.
Configuration requires that Miniconda3/Anaconda3 be properly downloaded and installed following these instructions. Deviation from these instructions can lead to issues when running the configuration or running the Python methods.
====Download Miniconda3====
 
# Open a browser and navigate to here: [https://docs.conda.io/en/latest/miniconda.html https://docs.conda.io/en/latest/miniconda.html]
 
# Pick a link pertaining to your machine that explicitly states Miniconda3 in the hyperlink. If running macOS, select the .pkg installer. Run the installer.
=====Python configuration video=====
# You may be asked to install for just the user, select this option.
# Using MATLAB: https://eigenvector.com/aiovg_videos/python-configuration-for-pls_toolbox/
:* Here is what this step looks like on Windows:
 
::[[Image:Miniconda_install_as.PNG|400px]]
 
:* Here is what this step looks like on macOS. Click on the 'Change Install Button' like below:
=====Download Miniconda3/Anaconda3=====
::[[Image:Miniconda_install_as_mac2.png|400px]]
# If using Miniconda3
:: And select 'Install for me only'
## Open a browser and navigate to Miniconda's site: [https://docs.conda.io/en/latest/miniconda.html https://docs.conda.io/en/latest/miniconda.html]
::[[Image:Miniconda_install_as_mac1.png|400px]]
## Pick a link pertaining to your machine that explicitly states Miniconda3 in the hyperlink. The particular version associated with each of the installers is not important, any of these should work fine. If running macOS, select the .pkg installer.
:4. If asked to add to System Path, do so.
## Run the installer, place software you know you have sufficient access to when it prompts you where you would like for it to be located on your machine.
## If asked to add to the System Path, do so. Ignore the message saying that doing this is not recommended.
# If using Anaconda3
## Open a browser and navigate to Anaconda's download site: [https://www.anaconda.com/products/distribution https://www.anaconda.com/products/distribution]
## Click '''Download'''
## Run the installer, place software you know you have sufficient access to when it prompts you where you would like for it to be located on your machine.
## If asked to add to the System Path, do so. Ignore the message saying that doing this is not recommended.
:5. Finish installation.
:5. Finish installation.
====Configure in MATLAB====
=====Configuration step in MATLAB=====
If the user has PLS_Toolbox and has ran <code>evriinstall</code>, open a new MATLAB instance and execute <code>config_pyenv</code> in the Command Window.
Once PLS_Toolbox has been installed in MATLAB, launch MATLAB and execute <code>config_pyenv</code> in the Command Window.
The output of this function should resemble closely to the screenshot below. The version of Python being used is 3.8, and there is a PLS_Toolbox insignia in most of the fields of <code>pyenv</code>
Successful configuration results in the message <code>Your pyenv was configured successfully!</code> on the command line, and subsequent execution of <code>pyenv</code> on the MATLAB command line produces output which should closely resemble what is displayed below
:[[Image:Pyenv_screenshot.PNG|700px]]
:[[Image:Pyenv_screenshot.PNG|700px]]
====Configure Solo====


=====Configuration step in Solo=====
Open Solo and configure Python by going to '''Edit'''>'''Options'''>'''Python'''>'''Configure Python with Conda''', like in the screenshot below.
[[Image:Config_solo.png|600px]]
Once completed, there will be a window that prompts a successful configuration if no issues arise:
[[File: pyenvsuccess.png]]
===Archived Solution===
Used when <code>options.source='archived'</code>. Follow the steps below to create your virtual environment via an archived file provided by our helpdesk.
====What's needed====
An archived file with the compressed Python environment. This is only available upon request to our helpdesk at helpdesk@eigenvector.com.
Note: The configuration can take a couple of minutes to complete. The PLS_Toolbox virtual environment can take between 1-2 GB of space.
A Python virtual environment is a setup denoting the version of Python being used as well as the packages and their versions. Virtual environments are created to organize these setups, and usually are created on a project-to-project basis. This PLS_Toolbox virtual environment is tailored for the user to use the Python methods in the toolbox. '''It is advised to not modify, add, or delete packages from this environment. We cannot guarantee that the software will work after modifications.'''
====How to configure====
No additional software is needed unlike the Conda solution. Just get the archived file from the helpdesk. Once downloaded on your machine, you will have to place it in directory of your choosing. Please choose a directory where you know you have sufficient rights. You will be prompted where this folder is located when running <code>config_pyenv</code>. You will start the configuration by choosing the archive file, which may look similar to what's below (no need to unzip or extract the archived file):
[[File:Pythonarchivedfileselection.png|700px]]
then click <b>Open</b>.
=====Configuration step in MATLAB=====
Once PLS_Toolbox has been installed in MATLAB, launch MATLAB and execute the following in the Command Window:
<pre>
options = config_pyenv('options');
options.source = 'archived';
result = config_pyenv(options);
</pre>
Successful configuration results in the message <code>Your pyenv was configured successfully!</code> on the command line, and subsequent execution of <code>pyenv</code> on the MATLAB command line produces output which should closely resemble what is displayed below (archived file was downloaded to folder called <code>archive_env_config</code>.
:[[Image:Pyenv_screenshot_archive.PNG|700px]]
=====Configuration step in Solo=====
Open Solo and configure Python by going to '''Edit'''>'''Options'''>'''Python'''>'''Configure Python with Archived File''', like in the screenshot below.
[[File:Config solo archive.png|600px]]
Once completed, there will be a window that prompts a successful configuration if no issues arise:
[[File: pyenvsuccess.png]]


===Testing configuration===
===Testing configuration===
It's important to see that the configration worked and that there is no unexpected behavior from Python. Follow the testing protocols below.
 
It's important to see that the configuration worked and that there is no unexpected behavior from Python. Follow the testing protocols below.
====Test in MATLAB====
====Test in MATLAB====
To make sure that PLS_Toolbox and Python are working correctly, run one of the demo scripts that uses Python:
To make sure that PLS_Toolbox and Python are working correctly, run one of the demo scripts that uses Python:
Line 54: Line 134:
# umapdemo
# umapdemo
# anndldemo (change line 35 to <code>options.algorithm = 'tensorflow'</code> to use Tensorflow)
# anndldemo (change line 35 to <code>options.algorithm = 'tensorflow'</code> to use Tensorflow)
# anndldemo (change line 70 to <code>options.algorithm = 'tensorflow'</code> to use Tensorflow)
# anndldademo (change line 70 to <code>options.algorithm = 'tensorflow'</code> to use Tensorflow)


If there are issues doing this, see the Troubleshooting section.
If there are issues doing this, see the Troubleshooting section.
====Test in Solo====
====Test in Solo====
Open one the Analysis Windows that uses Python and build a model to make sure that PLS_Toolbox and Python are working correctly.
Open one the Analysis Windows that uses Python and build a model to make sure that Solo and Python are working correctly.


If there are issues doing this, see the Troubleshooting section.
If there are issues doing this, see the Troubleshooting section.


===Undo configuration===
===Undo configuration===
If there comes a time that a user wants to undo this configuration, the user has two options: delete the PLS_Toolbox virtual environment or delete Miniconda3 (this also deletes the PLS_Toolbox virtual environment). See below how to do either of these options.
If there comes a time that a user wants to undo this configuration, the user has two options: delete the PLS_Toolbox virtual environment or delete Miniconda3. See below how to do either of these options.
'''Note: Deleting Miniconda3 will remove the PLS_Toolbox virtual environment, as well as any other virtual environments you may have created. Please use with caution.'''
 
====Undo in MATLAB====
====Undo in MATLAB====
* If the user would like to remove just the PLS_Toolbox virtual environment (and keep Miniconda3), run the following in the Command Window in MATLAB: <code>undo_config_pyenv</code>.
* If the user would like to remove just the PLS_Toolbox virtual environment, run the following in the Command Window in MATLAB: <code>undo_config_pyenv</code>.
* If the user would like to remove Miniconda3 (as well as the PLS_Toolbox virtual environment), run the following in the Command Window in MATLAB: <code>undo_config_pyenv('all') </code>.
* If the user would like to remove Miniconda3/Anaconda3 (as well as the PLS_Toolbox virtual environment), run the following in the Command Window in MATLAB:  
<pre>
options = undo_config_pyenv('options');
options.remove_all = 'yes';
result = undo_config_pyenv(options);
</pre>
 
====Undo in Solo====
====Undo in Solo====
* If the user would like to remove just the PLS_Toolbox virtual environment (and keep Miniconda3)
* If the user would like to remove just the PLS_Toolbox virtual environment (and keep Miniconda3)
** Open Solo and go to '''Edit'''>'''Options'''>'''Python'''>'''Remove PLS_Toolbox Python Environment'''.
* If the user would like to remove Miniconda3 (as well as the PLS_Toolbox virtual environment)
* If the user would like to remove Miniconda3 (as well as the PLS_Toolbox virtual environment)
** Open Solo and go to '''Edit'''>'''Options'''>'''Python'''>'''Remove Miniconda3/Anaconda3'''.


===Configuration tutorial videos===


===Troubleshooting===
===Troubleshooting===
* If MATLAB/Solo crashes when trying to run one of these methods:
* If MATLAB/Solo crashes when trying to run one of these methods:
** If running Windows, contact our helpdesk at helpdesk@eigenvector.com.
** From MATLAB
** If running macOS or Linux, start up a new session of MATLAB and type <code>py.sys.setdlopenflags(py.int(10));</code> in the Command Window, then rerun the method that caused the crash. If the crashing persists, contact our helpdesk at helpdesk@eigenvector.com.
*** If the PLS_Toolbox virtual environment is in fact being used, then from MATLAB run <code>check_pyenv</code>. If there are warnings, rerun <code>config_pyenv</code>
** From Solo
*** Click '''Edit>Options>Python>Check Environment Status'''. If there are warnings, click '''Configure Python'''.
* If there is an error along the lines of <code>Unable to resolve py.anything_can_be_here</code>
* If there is an error along the lines of <code>Unable to resolve py.anything_can_be_here</code>
** Type <code>pyenv</code> in the Command Window and ensure the PLS_Toolbox is being used.
** From MATLAB
** If the PLS_Toolbox virtual environment is in fact being used, then from MATLAB run <code>check_pyenv</code>. If there are warnings, rerun <code>config_pyenv</code>
*** Type <code>pyenv</code> in the Command Window and ensure the PLS_Toolbox is being used.
** If the above two steps do not resolve the issue, contact our helpdesk at helpdesk@eigenvector.com.
*** If running macOS or Linux, start up a new session of MATLAB and type <code>py.sys.setdlopenflags(py.int(10));</code> in the Command Window, then rerun the method that caused the crash. If the crashing persists, contact our helpdesk at helpdesk@eigenvector.com.
*** If the PLS_Toolbox virtual environment is in fact being used, then from MATLAB run <code>check_pyenv</code>. If there are warnings, rerun <code>config_pyenv</code>
** From Solo
*** Click '''Edit>Options>Python>Check Environment Status'''. If there are warnings, click '''Configure Python'''.
 
===See Also===
 
[[anndl]], [[anndlda]], [[tsne]], [[umap]], [[python]]

Latest revision as of 10:17, 28 August 2023

Purpose

Creates a Python virtual environment for PLS_Toolbox, giving access to evrimodel objects that use Python. Applicable for PLS_Toolbox/Solo 9.0 and newer. The correct version of Python, and its necessary packages, will be installed or built for you.

Synopsis

result = config_pyenv(options);

Options

options = a structure array with the following fields:

  • source: [ {'conda'} | 'archived' ], The source of which Python is built and configured for PLS_Toolbox/Solo. When source='conda', a virtual environment is built using Miniconda/Anaconda. If source='archived', then the Python comes from an archived file. This file is available upon request to our helpdesk starting in 9.1.
  • silent: [ {'no'} | 'yes' ], Governs the level of user-input needed. A dialog box is created asking the user if they would like to continue with the configuration when silent='no'. No dialog box is created when silent='yes'.


Methods Required for Configuration

Below shows a table of the PLS_Toolbox methods that use Python. The table also shows the corresponding Python package used to run each method. Without the proper configuration, access is denied to all of these methods.

PLS_Toolbox Method Python Package
TSNE Scikit-Learn
UMAP Umap-Learn
ANNDL Scikit-Learn & Tensorflow
ANNDLDA Scikit-Learn & Tensorflow


Important Note: Python in PLS_Toolbox/Solo for Apple Silicon devices is not fully supported yet.

Conda Solution

Used when options.source='conda'. This is the default method when running config_pyenv. Follow the steps below to create your virtual environment via Miniconda/Anaconda.


What's needed

  • Either one of Miniconda3 or Anaconda3 (The ability to use Anaconda with PLS_Toolbox is for versions 9.1 and newer)
    • Both of these are Python virtual environment management softwares. The management software is what's used to help build and maintain the PLS_Toolbox virtual environment. Instructions to download and install are located below. Miniconda3 is an abbreviated version of Anaconda3 that takes less space but does not have a user interface. Anaconda3 contains more packages and includes a nice interface for interaction, but takes much more space. We recommend Miniconda3 if you are new to either of these softwares. See this link to decide which is best for you: https://docs.conda.io/projects/conda/en/latest/user-guide/install/download.html#anaconda-or-miniconda. If you already have either of these, ensure that it has been added to the System Path for the configuration in MATLAB/Solo to work correctly.
  • MATLAB R2020b or newer/ Solo 9.0 or newer
    • This requirement allows the use of recent versions of Python and its packages.
  • Internet connection for Miniconda3/Anaconda3 download and Python configuration

Note: The configuration can take a couple of minutes to complete. The PLS_Toolbox virtual environment can take between 1-2 GB of space.

A Python virtual environment is a setup denoting the version of Python being used as well as the packages and their versions. Virtual environments are created to organize these setups, and usually are created on a project-to-project basis. This PLS_Toolbox virtual environment is tailored for the user to use the Python methods in the toolbox. It is advised to not modify, add, or delete packages from this environment. We cannot guarantee that the software will work after modifications.

How to configure

Configuration requires that Miniconda3/Anaconda3 be properly downloaded and installed following these instructions. Deviation from these instructions can lead to issues when running the configuration or running the Python methods.


Python configuration video
  1. Using MATLAB: https://eigenvector.com/aiovg_videos/python-configuration-for-pls_toolbox/


Download Miniconda3/Anaconda3
  1. If using Miniconda3
    1. Open a browser and navigate to Miniconda's site: https://docs.conda.io/en/latest/miniconda.html
    2. Pick a link pertaining to your machine that explicitly states Miniconda3 in the hyperlink. The particular version associated with each of the installers is not important, any of these should work fine. If running macOS, select the .pkg installer.
    3. Run the installer, place software you know you have sufficient access to when it prompts you where you would like for it to be located on your machine.
    4. If asked to add to the System Path, do so. Ignore the message saying that doing this is not recommended.
  2. If using Anaconda3
    1. Open a browser and navigate to Anaconda's download site: https://www.anaconda.com/products/distribution
    2. Click Download
    3. Run the installer, place software you know you have sufficient access to when it prompts you where you would like for it to be located on your machine.
    4. If asked to add to the System Path, do so. Ignore the message saying that doing this is not recommended.
5. Finish installation.
Configuration step in MATLAB

Once PLS_Toolbox has been installed in MATLAB, launch MATLAB and execute config_pyenv in the Command Window. Successful configuration results in the message Your pyenv was configured successfully! on the command line, and subsequent execution of pyenv on the MATLAB command line produces output which should closely resemble what is displayed below

Pyenv screenshot.PNG


Configuration step in Solo

Open Solo and configure Python by going to Edit>Options>Python>Configure Python with Conda, like in the screenshot below. Config solo.png


Once completed, there will be a window that prompts a successful configuration if no issues arise:


Pyenvsuccess.png

Archived Solution

Used when options.source='archived'. Follow the steps below to create your virtual environment via an archived file provided by our helpdesk.


What's needed

An archived file with the compressed Python environment. This is only available upon request to our helpdesk at helpdesk@eigenvector.com.

Note: The configuration can take a couple of minutes to complete. The PLS_Toolbox virtual environment can take between 1-2 GB of space.

A Python virtual environment is a setup denoting the version of Python being used as well as the packages and their versions. Virtual environments are created to organize these setups, and usually are created on a project-to-project basis. This PLS_Toolbox virtual environment is tailored for the user to use the Python methods in the toolbox. It is advised to not modify, add, or delete packages from this environment. We cannot guarantee that the software will work after modifications.


How to configure

No additional software is needed unlike the Conda solution. Just get the archived file from the helpdesk. Once downloaded on your machine, you will have to place it in directory of your choosing. Please choose a directory where you know you have sufficient rights. You will be prompted where this folder is located when running config_pyenv. You will start the configuration by choosing the archive file, which may look similar to what's below (no need to unzip or extract the archived file):

Pythonarchivedfileselection.png

then click Open.


Configuration step in MATLAB

Once PLS_Toolbox has been installed in MATLAB, launch MATLAB and execute the following in the Command Window:

options = config_pyenv('options');
options.source = 'archived';
result = config_pyenv(options);

Successful configuration results in the message Your pyenv was configured successfully! on the command line, and subsequent execution of pyenv on the MATLAB command line produces output which should closely resemble what is displayed below (archived file was downloaded to folder called archive_env_config.

Pyenv screenshot archive.PNG


Configuration step in Solo

Open Solo and configure Python by going to Edit>Options>Python>Configure Python with Archived File, like in the screenshot below. Config solo archive.png


Once completed, there will be a window that prompts a successful configuration if no issues arise:


Pyenvsuccess.png

Testing configuration

It's important to see that the configuration worked and that there is no unexpected behavior from Python. Follow the testing protocols below.

Test in MATLAB

To make sure that PLS_Toolbox and Python are working correctly, run one of the demo scripts that uses Python:

  1. tsnedemo
  2. umapdemo
  3. anndldemo (change line 35 to options.algorithm = 'tensorflow' to use Tensorflow)
  4. anndldademo (change line 70 to options.algorithm = 'tensorflow' to use Tensorflow)

If there are issues doing this, see the Troubleshooting section.

Test in Solo

Open one the Analysis Windows that uses Python and build a model to make sure that Solo and Python are working correctly.

If there are issues doing this, see the Troubleshooting section.

Undo configuration

If there comes a time that a user wants to undo this configuration, the user has two options: delete the PLS_Toolbox virtual environment or delete Miniconda3. See below how to do either of these options. Note: Deleting Miniconda3 will remove the PLS_Toolbox virtual environment, as well as any other virtual environments you may have created. Please use with caution.

Undo in MATLAB

  • If the user would like to remove just the PLS_Toolbox virtual environment, run the following in the Command Window in MATLAB: undo_config_pyenv.
  • If the user would like to remove Miniconda3/Anaconda3 (as well as the PLS_Toolbox virtual environment), run the following in the Command Window in MATLAB:
options = undo_config_pyenv('options');
options.remove_all = 'yes';
result = undo_config_pyenv(options);

Undo in Solo

  • If the user would like to remove just the PLS_Toolbox virtual environment (and keep Miniconda3)
    • Open Solo and go to Edit>Options>Python>Remove PLS_Toolbox Python Environment.
  • If the user would like to remove Miniconda3 (as well as the PLS_Toolbox virtual environment)
    • Open Solo and go to Edit>Options>Python>Remove Miniconda3/Anaconda3.


Troubleshooting

  • If MATLAB/Solo crashes when trying to run one of these methods:
    • From MATLAB
      • If the PLS_Toolbox virtual environment is in fact being used, then from MATLAB run check_pyenv. If there are warnings, rerun config_pyenv
    • From Solo
      • Click Edit>Options>Python>Check Environment Status. If there are warnings, click Configure Python.
  • If there is an error along the lines of Unable to resolve py.anything_can_be_here
    • From MATLAB
      • Type pyenv in the Command Window and ensure the PLS_Toolbox is being used.
      • If running macOS or Linux, start up a new session of MATLAB and type py.sys.setdlopenflags(py.int(10)); in the Command Window, then rerun the method that caused the crash. If the crashing persists, contact our helpdesk at helpdesk@eigenvector.com.
      • If the PLS_Toolbox virtual environment is in fact being used, then from MATLAB run check_pyenv. If there are warnings, rerun config_pyenv
    • From Solo
      • Click Edit>Options>Python>Check Environment Status. If there are warnings, click Configure Python.

See Also

anndl, anndlda, tsne, umap, python