Choose Language Hide Translation Bar

Anaconda Environments Integration

Anaconda is one of the most used Python distributions for Data Science, as it makes it very easy to install pre-tested libraries along with their dependencies. Anaconda allows the user to organize the installed libraries in virtual environments to prevent said dependencies from interfering with each other. This script allows a JMP user to take advantage of this feature in order to keep its Python dependencies separated and well organized.

 

The attached Anaconda.jsl script allows a user to specify an Anaconda environment to execute Python code that depends on the specific dependency versions installed in that environment. It does so by providing a wrapper around the Python Init() command that identifies the required arguments that will make it match the given Anaconda environment. For example:

 

conda = Include("anaconda.jsl");
If(!conda:init(1), // debug mode
	Show(Get Current Directory());
	Throw("Conda initialization failed."));
Show(conda:get_envs());
// change as appropriate; use a Python 3.6 Conda environment name.
// 3.7 supported but must be specified
my_env = "py3"; If(!conda:is_env(my_env), Throw("Bad Conda environment, please use another one.")); conda:launch_env(my_env, 1); // debug mode Python Submit("\[ import numpy as np v = np.array([[1, 2], [3, 4]]) d = int(np.linalg.det(v)) print(d) ]\" ); dNum = Python Get(d); Show(dNum);

The attached .zip file includes other examples, including one that uses the Python libraries requests and beautifulSoup4 to web scrape data for analysis in JMP.

For more details on creating and re-using Anaconda virtual environments, see:

Current limitations:

  • Anaconda detection only works on Windows for now;
  • conda.exe must be in your PATH;
  • All examples work fine in 15.1. All examples with the exception of goldenglobes.jsl (the web scraping example) work on 14.3.
Comments

Hi,

 

I would like to initial R using Anaconda. Do you have any suggestions? The following are examples I tried to access R via Anaconda but failed.

 

//Works
Set Environment Variable( "R_HOME", "C:\Users\UserName\Documents\R\R-3.6.1");
R init();
//TKIntRJMP.R version 14.0
//0
R term();

//Error
Set Environment Variable( "R_HOME", "C:\Users\UserName\AppData\Local\Continuum\anaconda3\envs\rstudio-1.1.456\lib\R");
R init();
//DLL:"C:\Users\UserName\AppData\Local\Continuum\anaconda3\envs\rstudio-1.1.456\lib\R\bin\x64\R.dll"
//-1
R term();

Also, I am not sure which "conda.exe" should I put in my path. Could you offer an example path? The "where.exe" also applied in your script. Should I put it in the same path as well?

 

 

Hi @Tzu-Chun,

I only tested this package with Python, I am not sure it would work with R as well. I also didn't find anything on our internal documentation about using 'R init' with the Anaconda distribution. It could very well be that the assumptions about where to find the required DLL files are not the same.

The location for conda.exe will depend on where you installed it, so it will be different for every user. Mine is at:

c:\home\bin\Anaconda3\Scripts\conda.exe

where.exe is the command that allows the script to work regardless of where conda is installed in your system. It is a Windows command so it should already be in your path.

 

 

That is really helpful. I'll test the code in my device and see if I can find an idea to connect R in Anaconda. Thanks again for your help and suggestions.

Article Tags
Contributors